Domanda

I try to set my socket to non-blocking mode using ioctlsocket, but it returns -1 and WSAGetLastError returns 10045 - Operation not supported. Why could that happen?

The code I write is rather specific, because it's not C++, but Lisp with Foreign Language Interface (it allows calling C and C++ functions from dll's), but really it doesn't matter, because everything else does work.

Here is the code:

(defconstant FIONBIO #x5421)
(setf socket-descriptor (socket AF_INET SOCK_STREAM IPPROTO_TCP))
...
(fli:with-dynamic-foreign-objects ((no-block (:unsigned :long) :initial-element 1))
  (ioctlsocket socket-descriptor FIONBIO no-block))
...

socket-descriptor - is just a socket descriptor, created with standard function socket

FIONBIO - a constant, I've found it's value just by googling it

no-block - a pointer to u_long, value of th u_long is 1.

ioctlsocket returns -1 and WSAGetLastError returns 10045.

È stato utile?

Soluzione

If it helps at all, the error 10045 you get from WSAGetLastError is described as follows:

enter image description here

EDIT
On my Windows system, I checked the value of FIONBIO in the debugger, and it should be 0x8004667E.

It's defined like this in both winsock.h and winsock2.h in the Windows 8 SDK:

#define _IOW(x,y,t)  (IOC_IN|(((long)sizeof(t)&IOCPARM_MASK)<<16)|((x)<<8)|(y))
#define FIONBIO      _IOW('f', 126, u_long) /* set/clear non-blocking i/o */

If you set an unsigned int equal to FIONBIO, then 0x8004667E is what you get.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top