Browse Source

add io_socketpair

master
Felix von Leitner 16 years ago
parent
commit
5959a6d634
3 changed files with 29 additions and 0 deletions
  1. +3
    -0
      CHANGES
  2. +2
    -0
      io.h
  3. +24
    -0
      io/io_socketpair.c

+ 3
- 0
CHANGES View File

@@ -1,3 +1,6 @@
0.19:
add io_socketpair

0.18:
make libowfat compile on BSD again (sorry, and thanks to everyone who
sent me a patch :-D)


+ 2
- 0
io.h View File

@@ -12,6 +12,8 @@ int io_readfile(int64* d,const char* s);
int io_createfile(int64* d,const char* s);
/* like pipe(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 */
int64 io_tryread(int64 d,char* buf,int64 len);


+ 24
- 0
io/io_socketpair.c View File

@@ -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