code to solve "SOCK_NONBLOCK" and "O_NONBLOCK" undefined problem in linux
2011-01-18 05:09
811 查看
#if defined(SOCK_NONBLOCK)
return ::socket(AF_INET, SOCK_STREAM | SOCK_NONBLOCK, IPPROTO_TCP);
/* If they have O_NONBLOCK, use the Posix way to do it */
#elif defined(O_NONBLOCK)
/* Fixme: O_NONBLOCK is defined but broken on SunOS 4.1.x and AIX 3.2.5. */
int sock = socket(PF_INET, SOCK_STREAM, 0);
int flags;
if (-1 == (flags = fcntl(sock, F_GETFL, 0)))
flags = 0;
fcntl(sock, F_SETFL, flags | O_NONBLOCK);
return sock;
#else
int sock = socket(PF_INET, SOCK_STREAM, 0);
/* Otherwise, use the old way of doing it */
int flags = 1;
ioctl(sock, FIOBIO, &flags);
return sock;
#endif
return ::socket(AF_INET, SOCK_STREAM | SOCK_NONBLOCK, IPPROTO_TCP);
/* If they have O_NONBLOCK, use the Posix way to do it */
#elif defined(O_NONBLOCK)
/* Fixme: O_NONBLOCK is defined but broken on SunOS 4.1.x and AIX 3.2.5. */
int sock = socket(PF_INET, SOCK_STREAM, 0);
int flags;
if (-1 == (flags = fcntl(sock, F_GETFL, 0)))
flags = 0;
fcntl(sock, F_SETFL, flags | O_NONBLOCK);
return sock;
#else
int sock = socket(PF_INET, SOCK_STREAM, 0);
/* Otherwise, use the old way of doing it */
int flags = 1;
ioctl(sock, FIOBIO, &flags);
return sock;
#endif
相关文章推荐
- Export op results in error "EXP.EXE has encountered a problem and needs to
- How to solve the "undefined reference to '__sync_sub_and_fetch_4'" compilation problem
- How to solve the "undefined reference to '__sync_sub_and_fetch_4'" compilation problem
- How to solve "one or more projects in the solution were not loaded correctly" problem?
- How to solve "The installation source for this product is not available" problem?
- Get "Server Down" when retrieve the channel list in sopcast, how to solve it?
- Linux-Linux下安装redis报错"undefined reference to__sync_add_and_fetch_4"解决办法
- Try to use "twisted.enterprise.adbapi" accessing database nonblockingly in Twisted (failed)
- LINUX undefined reference to" 问题解决方法
- some encountered problem and the solve methods when install Matlab in Linux
- undefined reference to错误 和ORA-06553: PLS-306: wrong number or types of arguments in call to "OGC_X"
- how to solve "linux scp command not found"
- Robbie's Notes on File System Security in Linux (and comparison to Windows NT)
- How to solve problem caused when the CRT library and MFC libraries are linked in the wrong order
- Call to a member function addToChildGroup() on a non-object in app/code/core/Mage/Core/Block/Abstrac
- How to solve "java.lang.VerifyError: Expecting a stackmap frame at branch target 6 in method"
- iWatch报错: Fail to code sign "***" No valid signing identities (i.e. certificate and private key pair
- Glib交叉编译:g__cancellable_lock undeclared!&HEADER/C_IN undeclared!&undefined reference to "localeconv"
- Master the basics, and you'll be able to solve any problem!
- some encountered problem and the solve methods when install Matlab in Linux