question on WSAAccept()
- From: "chenzero" <somewhere@xxxxxxxxxxxxxxx>
- Date: Tue, 20 Jun 2006 16:55:22 +0800
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);
}
.
- Prev by Date: Re: Drivemap to native 2003 domain without domainregistration
- Next by Date: Re: Entire Network List is Empty
- Previous by thread: disable IM
- Next by thread: Browser master problems
- Index(es):
Relevant Pages
|