add io_socketpair

master
leitner 21 years ago
parent 173ee15e6c
commit 745c4affc5

@ -1,3 +1,6 @@
0.19:
add io_socketpair
0.18: 0.18:
make libowfat compile on BSD again (sorry, and thanks to everyone who make libowfat compile on BSD again (sorry, and thanks to everyone who
sent me a patch :-D) sent me a patch :-D)

@ -12,6 +12,8 @@ int io_readfile(int64* d,const char* s);
int io_createfile(int64* d,const char* s); int io_createfile(int64* d,const char* s);
/* like pipe(d) */ /* like pipe(d) */
int io_pipe(int64* d); int io_pipe(int64* d);
/* like socketpair() */
int io_socketpair(int64* d);
/* non-blocking read(), -1 for EAGAIN and -3+errno for other errors */ /* non-blocking read(), -1 for EAGAIN and -3+errno for other errors */
int64 io_tryread(int64 d,char* buf,int64 len); int64 io_tryread(int64 d,char* buf,int64 len);

@ -0,0 +1,24 @@
#include <sys/types.h>
#include <unistd.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <errno.h>
#include "io_internal.h"
int io_socketpair(int64* d) {
int fds[2];
if (socketpair(AF_UNIX,SOCK_STREAM,0,fds)==-1)
if (socketpair(AF_INET6,SOCK_STREAM,IPPROTO_TCP,fds)==-1)
if (socketpair(AF_INET,SOCK_STREAM,IPPROTO_TCP,fds)==-1)
return 0;
if (io_fd(fds[1])) {
if (io_fd(fds[0])) {
d[0]=fds[0];
d[1]=fds[1];
return 1;
}
io_close(fds[1]);
}
close(fds[0]);
return 0;
}
Loading…
Cancel
Save