Click here to Skip to main content
15,889,595 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: simple program Pin
mpapeo20-Mar-05 11:43
mpapeo20-Mar-05 11:43 
GeneralRe: simple program Pin
David Crow21-Mar-05 4:30
David Crow21-Mar-05 4:30 
GeneralRe: simple program Pin
mpapeo21-Mar-05 8:45
mpapeo21-Mar-05 8:45 
GeneralCSocket & closed connection Pin
pand_pl20-Mar-05 3:34
pand_pl20-Mar-05 3:34 
GeneralRe: CSocket & closed connection Pin
eli1502197920-Mar-05 4:40
eli1502197920-Mar-05 4:40 
GeneralRe: CSocket & closed connection Pin
pand_pl20-Mar-05 5:23
pand_pl20-Mar-05 5:23 
GeneralRe: CSocket & closed connection Pin
eli1502197920-Mar-05 21:04
eli1502197920-Mar-05 21:04 
GeneralRe: CSocket & closed connection Pin
pand_pl21-Mar-05 1:57
pand_pl21-Mar-05 1:57 
I did as You suggested, only in CSocket style:
DWORD ctl = 1;
socket->IOCtl(FIONBIO, &ctl);

I've rewritten my code:
CString Connection::read()
{
TCHAR c;
CString out;
DWORD numRead;

do
{
::Sleep(100);
socket->IOCtl(FIONREAD, &numRead);

if(numRead == 0)
{
int ret = socket->Receive(&c, 1);
if(ret == 0) valid = FALSE;
if(ret == SOCKET_ERROR)
{
if(socket->GetLastError() == WSAECONNRESET)
valid = FALSE;
}
if(!valid) return CString();
}
} while(numRead == 0);
int count = socket->Receive((void*)out.GetBuffer(numRead), numRead);
out.ReleaseBuffer(numRead);
out.TrimRight();

cout << "Connection->reading: index: " << index << ", count: " << count << ", msg: " << (LPCTSTR)out << endl;
return out;
}

void Connection::write(CString s)
{
CSingleLock singleLock(§ion);
singleLock.Lock();
s += "\n";
if(socket->IsBlocking()) socket->CancelBlockingCall();
int count = socket->Send((void*)s.GetBuffer(10), s.GetLength());
cout << "Connection->writing: index: " << index << ", count: " << count << ", msg: " << (LPCTSTR)s;
if(count == 0)
cout << "Error: " << socket->GetLastError() << endl;
}

I'm no so sure about the line: if(socket->IsBlocking()) socket->CancelBlockingCall(); but I was forced to add this, because with two clients connected to server, writing to one of them was generating error WSAEINPROGRESS.

socket->Receive() is function of CSocket base class: CAsyncSocket.

Thanks again.
GeneralProcess memory Usage Pin
zan yan20-Mar-05 2:27
zan yan20-Mar-05 2:27 
GeneralRe: Process memory Usage Pin
Aamir Butt21-Mar-05 0:35
Aamir Butt21-Mar-05 0:35 
GeneralRe: Process memory Usage Pin
David Crow21-Mar-05 4:38
David Crow21-Mar-05 4:38 
GeneralNeed uuid.lib for Visual Studio 6 (debug) Pin
lob19-Mar-05 23:56
lob19-Mar-05 23:56 
GeneralRe: Need uuid.lib for Visual Studio 6 (debug) Pin
Verolix20-Mar-05 6:22
Verolix20-Mar-05 6:22 
GeneralRe: Need uuid.lib for Visual Studio 6 (debug) Pin
lob20-Mar-05 23:10
lob20-Mar-05 23:10 
Questionhow can I post WM_UNICHAR message Pin
pavel070519-Mar-05 22:11
pavel070519-Mar-05 22:11 
AnswerRe: how can I post WM_UNICHAR message Pin
PJ Arends20-Mar-05 16:20
professionalPJ Arends20-Mar-05 16:20 
GeneralRe: how can I post WM_UNICHAR message Pin
pavel070520-Mar-05 19:17
pavel070520-Mar-05 19:17 
GeneralRe: how can I post WM_UNICHAR message Pin
ThatsAlok20-Mar-05 19:34
ThatsAlok20-Mar-05 19:34 
GeneralRe: how can I post WM_UNICHAR message Pin
pavel070520-Mar-05 20:21
pavel070520-Mar-05 20:21 
GeneralRe: how can I post WM_UNICHAR message Pin
ThatsAlok20-Mar-05 22:08
ThatsAlok20-Mar-05 22:08 
GeneralCompile errors Pin
steven1119-Mar-05 21:47
steven1119-Mar-05 21:47 
GeneralRe: Compile errors Pin
Mike Dimmick19-Mar-05 22:43
Mike Dimmick19-Mar-05 22:43 
GeneralRe: Compile errors Pin
steven1119-Mar-05 23:54
steven1119-Mar-05 23:54 
GeneralRe: Compile errors Pin
Michael Dunn20-Mar-05 5:56
sitebuilderMichael Dunn20-Mar-05 5:56 
GeneralRe: Compile errors Pin
steven1120-Mar-05 8:35
steven1120-Mar-05 8:35 

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.