On 05-08-2010 22:49, Dave Thompson wrote: >> From: owner-openssl-us...@openssl.org On Behalf Of Raj >> Sent: Thursday, 05 August, 2010 01:06 > >> I will describe my code snippet below >> >> The module for connecting to server >> >> SOCKET RequestSock; >> SOCKADDR_IN ClientAddr; >> RequestSock = >> WSASocket(AF_INET,SOCK_STREAM,0,NULL,0,WSA_FLAG_OVERLAPPED); > > I don't know much about 'OVERLAPPED' in Windows, but I think > it's something like 'nonblocking' in Unix.
Actually, this is the Win32 level way to do Asynchronous IO (AIO), meaning that the operation will happen immediately or in the background, without the cost of extra threads or buffering. The OS will hold on to your buffer pointer and other arguments and then signal completion by signaling the provided or event or (if no event is given), the socket itself. Once signaled, the buffers are yours again and the success/failure, transmitted length etc. are available. The actual transmission logic will usually happen in DMA, interrupt handlers etc. > >> pHost = gethostbyname(pcTargetURL); >> memset(&ClientAddr,0,sizeof(ClientAddr)); >> int iAddrLen = sizeof(ClientAddr); >> ClientAddr.sin_family = AF_INET; >> memcpy(&ClientAddr.sin_addr,pHost->h_addr, pHost->h_length); >> ClientAddr.sin_port = htons(atoi(pcPort)); >> if(0 != connect(RequestSock,(SOCKADDR *)&ClientAddr, >> sizeof(SOCKADDR_IN))) >> { >> closesocket(RequestSock); // Connection failed >> return false; >> } >> >> WSAOVERLAPPED SendOverlapped; >> DWORD dwSendDataLen = 0; >> WSABUF ClientRequestBuf; >> WSAEVENT SendEvent[1]; >> ClientRequestBuf.buf = pcData; >> ClientRequestBuf.len = strlen(pcData); >> SendEvent[0] = WSACreateEvent(); >> SendOverlapped.hEvent = SendEvent[0]; >> iRes = >> WSASend(RequestSock,&ClientRequestBuf,1,&dwSendDataLen,dwFlag, >> &SendOverlapped,NULL); >> // Sending data to the server >> > At this point, the send probably hasn't actually happened. > And if you call [WSA]Recv and it returns, it almost certainly > hasn't actually been done either. You probably have to do > some kind of synchronization with the .hEvent, following > whatever Windows rules are applicable. > Yep ______________________________________________________________________ OpenSSL Project http://www.openssl.org User Support Mailing List openssl-users@openssl.org Automated List Manager majord...@openssl.org