2

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.

4

1 回答 1

1

如果它有帮助,你得到的错误 10045WSAGetLastError描述如下:

在此处输入图像描述

编辑
在我的 Windows 系统上,我在调试器中检查了 的值FIONBIO,它应该是0x8004667E.

它在 Windows 8 SDKwinsock.hwinsock2.hWindows 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 */

如果你设置一个unsigned int等于FIONBIO,那么0x8004667E就是你得到的。

于 2013-04-24T06:37:00.067 回答