Click here to Skip to main content
15,919,613 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Pointer Validation dynamic_cast<> Pin
Swinefeaster17-Jul-03 10:05
Swinefeaster17-Jul-03 10:05 
GeneralWin98 vs WinNT Pin
Jim Crafton26-Jan-02 12:30
Jim Crafton26-Jan-02 12:30 
GeneralRe: Win98 vs WinNT Pin
567890123427-Jan-02 3:13
567890123427-Jan-02 3:13 
GeneralCode optimizations - script or compiled Pin
alex.barylski26-Jan-02 11:26
alex.barylski26-Jan-02 11:26 
GeneralRe: Code optimizations - script or compiled Pin
Rick York26-Jan-02 12:30
mveRick York26-Jan-02 12:30 
GeneralRe: Code optimizations - script or compiled Pin
alex.barylski26-Jan-02 13:01
alex.barylski26-Jan-02 13:01 
GeneralRe: Code optimizations - script or compiled Pin
markkuk27-Jan-02 19:56
markkuk27-Jan-02 19:56 
GeneralAccess violated Pin
Stephen Caldwell26-Jan-02 11:12
Stephen Caldwell26-Jan-02 11:12 
I think I have a fairly broken class. I try to locate the Access Violation but I just can't seem to find it. I've tried examing the call stack but all i get is a bunch of kernel addresses. Can someone check it out and tell if there is anything wrong?


Here is the .h file

#ifndef _KTRANSCEIVER_H_
#define _KTRANSCEIVER_H_

#pragma warning(disable: 4786)

#include "bfThread.h"
#include "kStreamServer.h"

#include <vector>

#define EOK 0x0F1
#define EBADSOCK 0x0F2

using std::vector;

class bfSocket;
class kTransceiver:public bfThread
{
private:
struct client_t
{
bfSocket* pSock;
client_info *clinfo;
};

vector< bfSocket* > m_pClients;
bfSocket* m_pSource;
string m_streamName;
source_info *info;

//Removes a client from list of clients
int cleanClients();
int removeClient(std::vector<bfSocket*>::iterator sock_i);
int removeAll();
void End();
protected:
public:
//Constructor
kTransceiver(bfSocket* pSource, source_info *_info);
~kTransceiver();

//Add a client to list of clients
int addClient(bfSocket* pClient, client_info *clinfo);

DWORD ThreadProc();

};

#endif

Here is the .cpp file
#pragma warning(disable:4786)
#include <vector>
#include <string>
#include "../include/kTransceiver.h"
#include "../include/bfSocket.h"

#define _CRTDBG_MAP_ALLOC
#include <stdlib.h>
#include <crtdbg.h>

kTransceiver::kTransceiver(bfSocket *pSource, source_info *_info)
{
if (pSource)
m_pSource = pSource;
else
m_pSource = NULL;

info = _info;
}

kTransceiver::~kTransceiver()
{
End();
}

int kTransceiver::addClient(bfSocket* pClient, client_info *clinfo)
{
string buffer;
string temp;

if (pClient && pClient->IsConnected())
{
//Client Greeting
if (clinfo->icy_metdata) //client uses icy
{
buffer = "ICY 200 OK\r\n";
buffer += "Icy-Name: ";
buffer += info->name;
buffer += "\r\n";
buffer += "Icy-Notice1:This must be a Winamp <www.winamp.com> compatible player.\r\n";
buffer += "Icy-Notice2:Katie Alpha 0.1\r\n\r\n";
}
else
{
//Send audiocast headers
buffer = "HTTP/1.0 200 OK\r\n";
buffer += "x-audiocast-name: ";
buffer += info->name;
buffer += "\r\n";
if (!info->description.empty())
{
buffer += "x-audiocast-description:";
buffer += info->description;
buffer += "\r\n";
}
if (!info->genre.empty())
{
buffer += "x-audiocast-genre: ";
buffer += info->genre;
buffer += "\r\n";
}
buffer +="\r\n\r\n";
}

pClient->Send(buffer, buffer.length());

//Add to list
BeginLock();
m_pClients.push_back(pClient);
EndLock();
}
else
{
if (pClient)
delete pClient;

return EBADSOCK;
}

return EOK;
}

int kTransceiver::removeClient(std::vector< bfSocket* >::iterator sock_i)
{
BeginLock();

delete *sock_i;
*sock_i = NULL;
m_pClients.erase(sock_i);

EndLock();
return EOK;
}

DWORD kTransceiver::ThreadProc()
{
string buffer;
std::vector<bfSocket*>::iterator i;
int read, sent, total, z;
BOOL tryagain = FALSE;

while(isRunning())
{
read = 0;
sent = 0;

//read from the source
read = m_pSource->Receive(buffer, 2046);

if (!m_pSource->IsConnected())
{
break;
}

//Send the data to the clients
BeginLock();
printf("Checking size: %d\n", m_pClients.size());
printf("Sending data...\n");
for (i = m_pClients.begin(); i != m_pClients.end(); i++)
{
if(m_pClients.size() > 0)//make sure there are clients to send the data to
{
total = 0;
tryagain = FALSE;
//try twice to write
for (z = 0; z < 2; z++)
{
while (total < read) //make sure that it all gets sent
{
sent = ((bfSocket*)*i)->Send(buffer, read);
if (sent <0)
{
printf("Unable to send data! Trying again...\n");
tryagain = TRUE;
break;
}
total += sent;
if (!((bfSocket*)*i)->IsConnected())
{
printf("Client %s disconnected.\n", ((bfSocket*)*i)->GetAddress());
tryagain=FALSE;
break;
}//if
}//while(sent < read)
if (tryagain)
{
Sleep(100);
}
else
break;
}//for
}
else
break;//if
}//for
cleanClients();
EndLock();
Sleep(100);

}//while(isRunning())

//destroy our source
delete m_pSource;
delete info;
removeAll();

return 0;
}

void kTransceiver::End()
{
bfThread::End();
}

int kTransceiver::removeAll()
{
std::vector<bfSocket*>::iterator i;

if (m_pClients.size() == 0)
return EOK;

for(i = m_pClients.begin(); i != m_pClients.end(); i++)
{
//disconnect the client
((bfSocket*)*i)->Disconnect();
//remove the socket
delete ((bfSocket*)*i);
}

return EOK;
}

int kTransceiver::cleanClients()
{
std::vector<bfSocket*>::iterator i;

BOOL bKeepChecking = FALSE;
printf("Cleaning Clients...\n");
if (m_pClients.size() == 0)
return EOK;

for (i = m_pClients.begin(); i != m_pClients.end(); i++)
{
//check if the client is disconnected
if (*i)
{
if (!((bfSocket*)*i)->IsConnected())
{
//client isn't connected so remove him
printf("Removing Client.\n");
removeClient(i);
bKeepChecking = TRUE;
break;
}
}
}

if (bKeepChecking)
cleanClients();

return EOK;
}

<b>S</b>tephen <b>C</b>aldwell
Blackfission, CEO
http://blackfission.myip.org:81

GeneralRe: Access violated Pin
Swinefeaster26-Jan-02 12:01
Swinefeaster26-Jan-02 12:01 
Generallocalhost Pin
Rickard Andersson2026-Jan-02 8:12
Rickard Andersson2026-Jan-02 8:12 
Generalcount words in file Pin
tbbooher26-Jan-02 8:04
tbbooher26-Jan-02 8:04 
GeneralRe: count words in file Pin
Jon Sagara26-Jan-02 8:17
Jon Sagara26-Jan-02 8:17 
GeneralRe: count words in file Pin
tbbooher26-Jan-02 12:33
tbbooher26-Jan-02 12:33 
GeneralRe: count words in file Pin
pba_28-Jan-02 8:48
pba_28-Jan-02 8:48 
GeneralCRecordset question Pin
jafrazee26-Jan-02 7:23
jafrazee26-Jan-02 7:23 
Generaloverloaded methods in idl Pin
Brian Bailey26-Jan-02 6:59
Brian Bailey26-Jan-02 6:59 
GeneralWindows programming !!! How to learn Pin
26-Jan-02 6:25
suss26-Jan-02 6:25 
GeneralRe: Windows programming !!! How to learn Pin
alex.barylski26-Jan-02 11:33
alex.barylski26-Jan-02 11:33 
GeneralCString Format("...") problem in UNICODE Pin
26-Jan-02 1:20
suss26-Jan-02 1:20 
GeneralRe: CString Format("...") problem in UNICODE Pin
Tim Deveaux26-Jan-02 4:21
Tim Deveaux26-Jan-02 4:21 
GeneralResizing a control. Pin
NullStream26-Jan-02 0:55
NullStream26-Jan-02 0:55 
GeneralRe: Resizing a control. Pin
Christian Graus26-Jan-02 0:56
protectorChristian Graus26-Jan-02 0:56 
GeneralRe: Resizing a control. Pin
NullStream26-Jan-02 1:52
NullStream26-Jan-02 1:52 
GeneralRe: Resizing a control. Pin
Christian Graus26-Jan-02 9:37
protectorChristian Graus26-Jan-02 9:37 
GeneralRe: Resizing a control. Pin
Ravi Bhavnani26-Jan-02 10:17
professionalRavi Bhavnani26-Jan-02 10:17 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.