socketpair

Perl select returning undef on sysread when using Windows, IPC::Open3, and IO::Socket->socketpair()

[亡魂溺海] 提交于 2019-12-23 02:50:52
问题 I found this example (posted by @ikegami) of a way to use IPC::Open3 on windows using sockets. The problem is that, when I run it, I get an error An existing connection was forcibly closed by the remote host on the sysread . The command runs, the select works correctly, but the sysread is getting an undef instead of the expected 0 for end of file. This behavior is not the same for all commands. If I change the command to echo Hello World! it does not cause the error. Any idea what is going on

Is it safe to read from pipe OR socketpair with one end closed till reaching EOF?

冷暖自知 提交于 2019-12-13 05:14:26
问题 Consider the following EXAMPLE code: #include <sys/socket.h> int main() { int sv[ 2 ] = { 0 }; socketpair( AF_UNIX, SOCK_STREAM | SOCK_CLOEXEC | SOCK_NONBLOCK, 0, sv ); for( unsigned ii = 0; ii < 5; ++ii ) { int* msg = new int( 123 ); if( -1 == send( sv[ 0 ], &msg, sizeof(int*), MSG_NOSIGNAL ) ) { delete msg; } } close( sv[0] ); sleep( 1 ); int* msg = 0; int r; while( ( r = read( sv[ 1 ], &msg, sizeof(int*) ) ) > 0 ) { delete msg; } return 0; } Obviously, the code works fine, but it doesn't

【原创】modb 功能设计之“跨线程通信”

北慕城南 提交于 2019-11-30 12:15:31
在《 modb 功能设计之“支持多消费者单生产者” 》中曾提到,需要解决“rabbitmq 线程与 sql 执行线程之间的跨线程通信手段”。本文针对这个问题进行一些说明。 【第一个版本】 使用 pipe 作为跨线程通信方式, 使用如下代码来支持 pipe: # 使用 _pipe 来模拟 pipe #if defined(WIN32) || defined(_WIN32) #include <io.h> #include <fcntl.h> #define pipe(fds) _pipe(fds, 4096, _O_BINARY) #endif 此时运行实现了 sql 线程的 demo,发现 sql 线程总是无法正常运行,在调用 libevent 接口 event_base_dispatch 时会有错误 “10038” 报出。最终查出的结论是: WSAENOTSOCK (10038) Socket operation on non-socket. 操作试图不是在套接字上进行。它可能是套接字句柄参数没有引用到一个合法套接字,或者是调用 select() 函数时,一个 fd_set 中的成员不合法。 查来查去,结果发现,就是 windows 下不能将 pipe(其实是 _pipe)和 select 一起使用的原因。因为 windows 平台上会认为 pipe 产生的 fd 不是一个合法的