question on WSAAccept()

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



Hello All,
On MSDN, it says that "A socket in nonblocking mode fails with the error
WSAEWOULDBLOCK when an application calls WSAAccept and no connections are
pending on the queue".
however, I found that the WSAAccept() always blocked.(following is the code)
and how to implementate accepting client in event mechanism ?
Thanks!
chenzero

void main(int argc, char* argv[])
{
int ret;
WSADATA wsaData;
WSAStartup(MAKEWORD(2,2), &wsaData);

// mark the socket with non-blocking
SOCKET listener = WSASocket(AF_INET, SOCK_STREAM, 0, NULL, 0,
WSA_FLAG_OVERLAPPED);
if ( listener == INVALID_SOCKET) {
cout <<"WSASocket() failed with error " << WSAGetLastError() <<endl;
return;
}


SOCKADDR_IN InternetAddr;
InternetAddr.sin_family = AF_INET;
InternetAddr.sin_addr.s_addr = htonl(INADDR_ANY);
InternetAddr.sin_port = htons(12345);

ret = bind(listener, (PSOCKADDR) &InternetAddr, sizeof(InternetAddr));
if (ret == SOCKET_ERROR) {
cout<<"bind() failed with error: " << IntToStr(
WSAGetLastError()).c_str() <<endl;
return;
}
if (listen(listener, 5) == SOCKET_ERROR) {
cout<< "*** listen() failed with error "<< WSAGetLastError() <<endl;
return;
}

struct sockaddr cc; int ccsize=sizeof(cc);
SOCKET accept = WSAAccept(listener, &cc, &ccsize, NULL, 0);
if (accept == INVALID_SOCKET) {
cout<<"socket error"<< WSAGetLastError() <<endl;
}

ret=WSACleanup();
assert(ret!=SOCKET_ERROR);

}



.



Relevant Pages

  • Re: question on WSAAccept()
    ... it says that "A socket in nonblocking mode fails with the error ... WSAEWOULDBLOCK when an application calls WSAAccept and no connections are ... SOCKET listener = WSASocket(AF_INET, SOCK_STREAM, 0, NULL, 0, ... ret = bind&InternetAddr, sizeof); ...
    (microsoft.public.win32.programmer.networks)
  • question on WSAAccept()
    ... it says that "A socket in nonblocking mode fails with the error ... WSAEWOULDBLOCK when an application calls WSAAccept and no connections are ... SOCKET listener = WSASocket(AF_INET, SOCK_STREAM, 0, NULL, 0, ... ret = bind&InternetAddr, sizeof); ...
    (microsoft.public.win32.programmer.networks)
  • Re: Linux 2.6.29.4
    ... static int is_efer_nx ... if (ret) ... struct ftdi_private { ... the specific security attributes of the socket ...
    (Linux-Kernel)
  • Re: Help With Using Socket To Download Word Document
    ... I'd remove the BinaryWriter entirely, there's no need for it, and is likely to confuse. ... fs.Write(buffer, 0, ret); ... Zero being returned by Available is quite different from zero being returned by Read. ... From Available (assuming that it behaves the same as the one on System.Net.Sockets.Socket) zero means *at this moment* there are no bytes to return; whereas on Read it means the peer has closed the socket, and thus there will *never* be any more bytes to read. ...
    (microsoft.public.win32.programmer.networks)
  • Re: Scalable tcp server
    ... Ignoring the issue of trying to send structs over a socket & the ... int nReadSoFar = 0; ... if ((ret = m_Socket.Recv( ... while I get errors on the client side and things just stop working. ...
    (comp.unix.programmer)