broken lose32 port using mingw (don't use!!!)

initial Solaris /dev/poll port
master
leitner 21 years ago
parent b81e8bcd27
commit 82a4ae868d

@ -14,6 +14,8 @@
need to try using mmap on OpenBSD and NetBSD to get zero-copy TCP.
guard against same event being signalled twice (confused our list
handling)
add support for Solaris /dev/poll
add lose32 support (broken, please don't use!)
0.16:
add buffer_fromsa (make buffer from stralloc)

@ -75,7 +75,7 @@ $(DNS_OBJS): dns.h stralloc.h taia.h tai.h uint64.h iopause.h
$(CASE_OBJS): case.h
$(ARRAY_OBJS): uint64.h array.h
$(MULT_OBJS): uint64.h uint32.h uint16.h safemult.h
$(IO_OBJS): uint64.h array.h io.h io_internal.h taia.h tai.h haveepoll.h havekqueue.h havesigio.h havebsdsf.h
$(IO_OBJS): uint64.h array.h io.h io_internal.h taia.h tai.h haveepoll.h havekqueue.h havesigio.h havebsdsf.h havedevpoll.h
iob_addbuf.o iob_addfile.o iob_new.o iob_reset.o iob_send.o: iob_internal.h iob.h
@ -132,7 +132,7 @@ t: t.o libowfat.a
clean:
rm -f *.o *.a *.da *.bbg *.bb core t haveip6.h haven2i.h \
havesl.h haveinline.h iopause.h select.h havekqueue.h haveepoll.h \
libepoll havesigio.h havebsdsf.h Makefile dep
libepoll havesigio.h havebsdsf.h havescope.h havedevpoll.h Makefile dep
INCLUDES=buffer.h byte.h fmt.h ip4.h ip6.h mmap.h scan.h socket.h str.h stralloc.h \
uint16.h uint32.h uint64.h open.h textcode.h tai.h taia.h dns.h iopause.h case.h \
@ -164,6 +164,11 @@ haveip6.h: tryip6.c
if $(DIET) $(CC) $(CFLAGS) -c tryip6.c >/dev/null 2>&1; then echo "#define LIBC_HAS_IP6"; fi > $@
-rm -f tryip6.o
havescope.h: tryscope.c
-rm -f $@
if $(DIET) $(CC) $(CFLAGS) -c tryscope.c >/dev/null 2>&1; then echo "#define LIBC_HAS_SCOPE_ID"; fi > $@
-rm -f tryscope.o
haven2i.h: tryn2i.c
-rm -f $@
if $(DIET) $(CC) $(CFLAGS) -o t tryn2i.c >/dev/null 2>&1; then echo "#define HAVE_N2I"; fi > $@
@ -195,6 +200,11 @@ haveepoll.h: tryepoll.c
if $(DIET) $(CC) $(CFLAGS) -o tryepoll tryepoll.c -lepoll >/dev/null 2>&1; then echo "#define HAVE_EPOLL 2"; fi; fi > $@
-rm -f tryepoll
havedevpoll.h: trydevpoll.c
-rm -f $@
if $(DIET) $(CC) $(CFLAGS) -c trydevpoll.c >/dev/null 2>&1; then echo "#define HAVE_DEVPOLL"; fi > $@
-rm -f trydevpoll.o
libepoll: haveepoll.h
if test "z`cat haveepoll.h`" = "z#define HAVE_EPOLL 2"; then echo -lepoll; fi > $@
@ -216,7 +226,7 @@ select.h: select.h1 select.h2 trysysel.c
socket_accept6.o socket_connect6.o socket_local6.o socket_mchopcount6.o \
socket_mcjoin6.o socket_mcleave6.o socket_mcloop6.o socket_recv6.o \
socket_remote6.o socket_send6.o socket_tcp6.o socket_udp6.o: haveip6.h
socket_remote6.o socket_send6.o socket_tcp6.o socket_udp6.o: haveip6.h havescope.h
socket_getifidx.o socket_getifname.o: haven2i.h
@ -226,7 +236,7 @@ socket_remote6.o: havesl.h
fmt_xlong.o scan_xlong.o fmt_ip6_flat.o $(TEXTCODE_OBJS): haveinline.h
dep: haveip6.h haven2i.h havesl.h haveinline.h iopause.h select.h haveepoll.h havekqueue.h
dep: haveip6.h haven2i.h havesl.h haveinline.h iopause.h select.h haveepoll.h havekqueue.h havedevpoll.h
gcc -I. -MM $(wildcard */*.c) t.c > dep
libdep:

@ -1,5 +1,8 @@
#include <unistd.h>
#include "buffer.h"
#ifdef __MINGW32__
#include <io.h>
#endif
char buffer_1_space[BUFFER_INSIZE];
static buffer it = BUFFER_INIT(write,1,buffer_1_space,sizeof buffer_1_space);

@ -45,7 +45,9 @@ void dns_random_init(const char data[128])
uint32_unpack(tpack + 4 * i,in + 4 + i);
in[8] = getpid();
#ifndef __MINGW32__
in[9] = getppid();
#endif
/* more space in 10 and 11, but this is probably enough */
}

@ -5,6 +5,9 @@
#include "str.h"
#include "openreadclose.h"
#include "dns.h"
#ifdef __MINGW32__
#include <winsock2.h>
#endif
static stralloc data = {0};

@ -1,5 +1,9 @@
#include <sys/types.h>
#ifdef WIN32
#include <winsock2.h>
#else
#include <sys/socket.h>
#endif
#include <unistd.h>
#include <stdlib.h>
#include "socket.h"

@ -4,5 +4,7 @@
#include "io_internal.h"
void io_closeonexec(int64 d) {
#ifndef __MINGW32__
fcntl(d,F_SETFL,fcntl(d,F_GETFL,0) | FD_CLOEXEC);
#endif
}

@ -11,6 +11,11 @@
#include <inttypes.h>
#include <sys/epoll.h>
#endif
#ifdef HAVE_DEVPOLL
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/devpoll.h>
#endif
void io_dontwantread(int64 d) {
int newfd;
@ -35,6 +40,15 @@ void io_dontwantread(int64 d) {
ts.tv_sec=0; ts.tv_nsec=0;
kevent(io_master,&kev,1,0,0,&ts);
}
#endif
#ifdef HAVE_DEVPOLL
if (io_waitmode==DEVPOLL) {
struct pollfd x;
x.fd=d;
x.events=0;
if (e->wantwrite) x.events|=POLLOUT;
write(io_master,&x,sizeof(x));
}
#endif
e->wantread=0;
}

@ -11,6 +11,11 @@
#include <inttypes.h>
#include <sys/epoll.h>
#endif
#ifdef HAVE_DEVPOLL
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/devpoll.h>
#endif
void io_dontwantwrite(int64 d) {
int newfd;
@ -35,6 +40,15 @@ void io_dontwantwrite(int64 d) {
ts.tv_sec=0; ts.tv_nsec=0;
kevent(io_master,&kev,1,0,0,&ts);
}
#endif
#ifdef HAVE_DEVPOLL
if (io_waitmode==DEVPOLL) {
struct pollfd x;
x.fd=d;
x.events=0;
if (e->wantread) x.events|=POLLIN;
write(io_master,&x,sizeof(x));
}
#endif
e->wantwrite=0;
}

@ -3,7 +3,8 @@
void io_eagain(int64 d) {
io_entry* e=array_get(&io_fds,sizeof(io_entry),d);
if (e) {
e->canread=0;
if (e->wantread) e->canread=0;
if (e->wantwrite) e->canwrite=0;
#ifdef HAVE_SIGIO
if (d==alt_firstread) {
debug_printf(("io_eagain: dequeueing %lld from alt read queue (next is %ld)\n",d,e->next_read));

@ -18,17 +18,26 @@
#include <sys/epoll.h>
#endif
#include <unistd.h>
#ifdef HAVE_DEVPOLL
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/devpoll.h>
#endif
/* put d on internal data structure, return 1 on success, 0 on error */
int io_fd(int64 d) {
long r;
io_entry* e;
#ifndef __MINGW32__
long r;
if ((r=fcntl(d,F_GETFL,0)) == -1)
return 0; /* file descriptor not open */
#endif
if (!(e=array_allocate(&io_fds,sizeof(io_entry),d))) return 0;
byte_zero(e,sizeof(io_entry));
e->inuse=1;
#ifndef __MINGW32__
if (r&O_NDELAY) e->nonblock=1;
#endif
e->next_read=e->next_write=-1;
if (io_waitmode==UNDECIDED) {
first_readable=first_writeable=-1;
@ -42,6 +51,12 @@ int io_fd(int64 d) {
if (io_master!=-1) io_waitmode=KQUEUE;
}
#endif
#if defined(HAVE_DEVPOLL)
if (io_waitmode==UNDECIDED) {
io_master=open("/dev/poll",O_RDWR);
if (io_master!=-1) io_waitmode=DEVPOLL;
}
#endif
#if defined(HAVE_SIGIO)
alt_firstread=alt_firstwrite=-1;
if (io_waitmode==UNDECIDED) {

@ -3,8 +3,23 @@
#include <errno.h>
#include "io_internal.h"
#ifdef __MINGW32__
#include <winsock2.h>
#include "windoze.h"
#endif
#ifndef O_NDELAY
#define O_NDELAY O_NONBLOCK
#endif
void io_nonblock(int64 d) {
io_entry* e=array_get(&io_fds,sizeof(io_entry),d);
#ifdef __MINGW32__
unsigned long i=1;
if (ioctlsocket( d, FIONBIO, &i)==0)
if (e) e->nonblock=1;
#else
if (fcntl(d,F_SETFL,fcntl(d,F_GETFL,0) | O_NDELAY)==0)
if (e) e->nonblock=1;
#endif
}

@ -2,9 +2,15 @@
#include "io_internal.h"
int io_pipe(int64* d) {
#ifdef __MINGW32__
HANDLE fds[2];
if (CreatePipe(fds,fds+1,0,0)==0)
return 0;
#else
int fds[2];
if (pipe(fds)==-1)
return 0;
#endif
if (io_fd(fds[1])) {
if (io_fd(fds[0])) {
d[0]=fds[0];

@ -14,6 +14,11 @@
#include <inttypes.h>
#include <sys/epoll.h>
#endif
#ifdef HAVE_DEVPOLL
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/devpoll.h>
#endif
int64 io_waituntil2(int64 milliseconds) {
struct pollfd* p;
@ -79,6 +84,38 @@ int64 io_waituntil2(int64 milliseconds) {
return n;
}
#endif
#ifdef HAVE_DEVPOLL
if (io_waitmode==DEVPOLL) {
dvpoll_t timeout;
struct pollfd y[100];
int n;
timeout.dp_timeout=milliseconds;
timeout.dp_nfds=100;
timeout.dp_fds=y;
if ((n=ioctl(io_master,DP_POLL,&timeout))==-1) return -1;
for (i=n-1; i>=0; --i) {
io_entry* e=array_get(&io_fds,sizeof(io_entry),y[--n].fd);
if (e) {
if (y[n].revents&(POLLERR|POLLHUP)) {
/* error; signal whatever app is looking for */
if (e->wantread) y[n].revents=POLLIN; else
if (e->wantwrite) y[n].revents=POLLOUT;
}
if (!e->canread && (y[n].revents==POLLIN)) {
e->canread=1;
e->next_read=first_readable;
first_readable=y[n].fd;
}
if (!e->canwrite && (y[n].revents==POLLOUT)) {
e->canwrite=1;
e->next_write=first_writeable;
first_writeable=y[i].fd;
}
}
}
return n;
}
#endif
#ifdef HAVE_SIGIO
if (io_waitmode==_SIGIO) {
siginfo_t info;

@ -14,6 +14,11 @@
#ifdef HAVE_SIGIO
#include <sys/poll.h>
#endif
#ifdef HAVE_DEVPOLL
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/devpoll.h>
#endif
void io_wantread(int64 d) {
int newfd;
@ -39,6 +44,15 @@ void io_wantread(int64 d) {
kevent(io_master,&kev,1,0,0,&ts);
}
#endif
#ifdef HAVE_DEVPOLL
if (io_waitmode==DEVPOLL) {
struct pollfd x;
x.fd=d;
x.events=POLLIN;
if (e->wantwrite) x.events|=POLLOUT;
write(io_master,&x,sizeof(x));
}
#endif
#ifdef HAVE_SIGIO
if (io_waitmode==_SIGIO) {
struct pollfd p;

@ -14,6 +14,11 @@
#ifdef HAVE_SIGIO
#include <sys/poll.h>
#endif
#ifdef HAVE_DEVPOLL
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/devpoll.h>
#endif
void io_wantwrite(int64 d) {
int newfd;
@ -39,6 +44,15 @@ void io_wantwrite(int64 d) {
kevent(io_master,&kev,1,0,0,&ts);
}
#endif
#ifdef HAVE_DEVPOLL
if (io_waitmode==DEVPOLL) {
struct pollfd x;
x.fd=d;
x.events=POLLOUT;
if (e->wantread) x.events|=POLLIN;
write(io_master,&x,sizeof(x));
}
#endif
#ifdef HAVE_SIGIO
if (io_waitmode==_SIGIO) {
struct pollfd p;

@ -2,12 +2,18 @@
#include "array.h"
#include "haveepoll.h"
#include "havekqueue.h"
#include "havedevpoll.h"
#include "havesigio.h"
#ifdef HAVE_SIGIO
#define _GNU_SOURCE
#include <signal.h>
#endif
#ifdef __MINGW32__
#include "socket.h"
extern HANDLE io_comport;
#endif
typedef struct {
unsigned int wantread:1;
unsigned int wantwrite:1;
@ -19,6 +25,10 @@ typedef struct {
long next_read;
long next_write;
void* cookie;
#ifdef __MINGW32__
OVERLAPPED o;
HANDLE fd;
#endif
} io_entry;
extern array io_fds;
@ -40,9 +50,12 @@ enum {
#ifdef HAVE_SIGIO
,_SIGIO
#endif
#ifdef HAVE_DEVPOLL
,DEVPOLL
#endif
} io_waitmode;
#if defined(HAVE_KQUEUE) || defined(HAVE_EPOLL)
#if defined(HAVE_KQUEUE) || defined(HAVE_EPOLL) || defined(HAVE_DEVPOLL)
extern int io_master;
#endif
#if defined(HAVE_SIGIO)

@ -1,10 +1,28 @@
#include <sys/types.h>
#include <unistd.h>
#ifdef __MINGW32__
#include <windows.h>
#else
#include <sys/mman.h>
#endif
#include "open.h"
#include "mmap.h"
extern char* mmap_private(const char* filename,unsigned long* filesize) {
char* mmap_private(const char* filename,unsigned long* filesize) {
#ifdef __MINGW32__
HANDLE fd,m;
char* map;
fd=CreateFile(filename,GENERIC_READ,FILE_SHARE_READ,0,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,0);
if (fd==INVALID_HANDLE_VALUE)
return 0;
m=CreateFileMapping(fd,0,PAGE_WRITECOPY,0,0,NULL);
map=0;
if (m)
map=MapViewOfFile(m,FILE_MAP_COPY,0,0,0);
CloseHandle(m);
CloseHandle(fd);
return map;
#else
int fd=open_read(filename);
char *map;
if (fd>=0) {
@ -16,4 +34,5 @@ extern char* mmap_private(const char* filename,unsigned long* filesize) {
return map;
}
return 0;
#endif
}

@ -1,10 +1,28 @@
#include <sys/types.h>
#include <unistd.h>
#ifdef __MINGW32__
#include <windows.h>
#else
#include <sys/mman.h>
#endif
#include "open.h"
#include "mmap.h"
extern char* mmap_read(const char* filename,unsigned long* filesize) {
#ifdef __MINGW32__
HANDLE fd,m;
char* map;
fd=CreateFile(filename,GENERIC_READ,FILE_SHARE_READ,0,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,0);
if (fd==INVALID_HANDLE_VALUE)
return 0;
m=CreateFileMapping(fd,0,PAGE_READONLY,0,0,NULL);
map=0;
if (m)
map=MapViewOfFile(m,FILE_MAP_READ,0,0,0);
CloseHandle(m);
CloseHandle(fd);
return map;
#else
int fd=open_read(filename);
char *map;
if (fd>=0) {
@ -16,4 +34,5 @@ extern char* mmap_read(const char* filename,unsigned long* filesize) {
return map;
}
return 0;
#endif
}

@ -1,10 +1,28 @@
#include <sys/types.h>
#include <unistd.h>
#ifdef __MINGW32__
#include <windows.h>
#else
#include <sys/mman.h>
#endif
#include "open.h"
#include "mmap.h"
extern char* mmap_shared(const char* filename,unsigned long* filesize) {
#ifdef __MINGW32__
HANDLE fd,m;
char* map;
fd=CreateFile(filename,GENERIC_WRITE,FILE_SHARE_WRITE,0,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,0);
if (fd==INVALID_HANDLE_VALUE)
return 0;
m=CreateFileMapping(fd,0,PAGE_READWRITE,0,0,NULL);
map=0;
if (m)
map=MapViewOfFile(m,FILE_MAP_WRITE,0,0,0);
CloseHandle(m);
CloseHandle(fd);
return map;
#else
int fd=open_read(filename);
char *map;
if (fd>=0) {
@ -16,4 +34,5 @@ extern char* mmap_shared(const char* filename,unsigned long* filesize) {
return map;
}
return 0;
#endif
}

@ -2,6 +2,10 @@
#include <fcntl.h>
#include "open.h"
extern int open_append(const char *filename) {
#ifndef O_NDELAY
#define O_NDELAY 0
#endif
int open_append(const char *filename) {
return open(filename,O_WRONLY|O_NDELAY|O_APPEND|O_CREAT,0600);
}

@ -2,6 +2,10 @@
#include <fcntl.h>
#include "open.h"
extern int open_excl(const char *filename) {
#ifndef O_NDELAY
#define O_NDELAY 0
#endif
int open_excl(const char *filename) {
return open(filename,O_WRONLY|O_NDELAY|O_TRUNC|O_CREAT|O_EXCL,0600);
}

@ -2,6 +2,10 @@
#include <fcntl.h>
#include "open.h"
extern int open_read(const char *filename) {
#ifndef O_NDELAY
#define O_NDELAY 0
#endif
int open_read(const char *filename) {
return open(filename,O_RDONLY|O_NDELAY);
}

@ -2,6 +2,10 @@
#include <fcntl.h>
#include "open.h"
extern int open_trunc(const char *filename) {
#ifndef O_NDELAY
#define O_NDELAY 0
#endif
int open_trunc(const char *filename) {
return open(filename,O_WRONLY|O_NDELAY|O_TRUNC|O_CREAT,0644);
}

@ -2,6 +2,10 @@
#include <fcntl.h>
#include "open.h"
extern int open_write(const char *filename) {
#ifndef O_NDELAY
#define O_NDELAY 0
#endif
int open_write(const char *filename) {
return open(filename,O_WRONLY|O_CREAT|O_NDELAY,0644);
}

@ -55,4 +55,47 @@ int socket_sendfile(int out,int in,uint32 offset,uint32 bytes);
int noipv6;
#ifdef __MINGW32__
#include <winsock2.h>
#include <ws2tcpip.h>
#define EWOULDBLOCK WSAEWOULDBLOCK
#define EINPROGRESS WSAEINPROGRESS
#define EALREADY WSAEALREADY
#define ENOTSOCK WSAENOTSOCK
#define EDESTADDRREQ WSAEDESTADDRREQ
#define EMSGSIZE WSAEMSGSIZE
#define EPROTOTYPE WSAEPROTOTYPE
#define ENOPROTOOPT WSAENOPROTOOPT
#define EPROTONOSUPPORT WSAEPROTONOSUPPORT
#define ESOCKTNOSUPPORT WSAESOCKTNOSUPPORT
#define EOPNOTSUPP WSAEOPNOTSUPP
#define EPFNOSUPPORT WSAEPFNOSUPPORT
#define EAFNOSUPPORT WSAEAFNOSUPPORT
#define EADDRINUSE WSAEADDRINUSE
#define EADDRNOTAVAIL WSAEADDRNOTAVAIL
#define ENETDOWN WSAENETDOWN
#define ENETUNREACH WSAENETUNREACH
#define ENETRESET WSAENETRESET
#define ECONNABORTED WSAECONNABORTED
#define ECONNRESET WSAECONNRESET
#define ENOBUFS WSAENOBUFS
#define EISCONN WSAEISCONN
#define ENOTCONN WSAENOTCONN
#define ESHUTDOWN WSAESHUTDOWN
#define ETOOMANYREFS WSAETOOMANYREFS
#define ETIMEDOUT WSAETIMEDOUT
#define ECONNREFUSED WSAECONNREFUSED
#define ELOOP WSAELOOP
#define EHOSTDOWN WSAEHOSTDOWN
#define EHOSTUNREACH WSAEHOSTUNREACH
#define EPROCLIM WSAEPROCLIM
#define EUSERS WSAEUSERS
#define EDQUOT WSAEDQUOT
#define ESTALE WSAESTALE
#define EREMOTE WSAEREMOTE
#define EDISCON WSAEDISCON
#endif
#endif

@ -1,6 +1,9 @@
#ifndef __MINGW32__
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#endif
#include "windoze.h"
#include "socket.h"
#include "havesl.h"
@ -8,7 +11,8 @@ int socket_accept4(int s,char *ip,uint16 *port) {
struct sockaddr_in si;
socklen_t len = sizeof si;
int fd;
if ((fd=accept(s,(struct sockaddr*) &si,&len))<0) return -1;
if ((fd=accept(s,(struct sockaddr*) &si,&len))==-1)
return winsock2errno(-1);
*(uint32*)ip = *(uint32*)&si.sin_addr;
uint16_unpack_big((char *) &si.sin_port,port);
return fd;

@ -1,12 +1,16 @@
#include <sys/param.h>
#include <sys/types.h>
#ifndef __MINGW32__
#include <sys/socket.h>
#include <netinet/in.h>
#endif
#include "windoze.h"
#include "byte.h"
#include "socket.h"
#include "ip6.h"
#include "haveip6.h"
#include "havesl.h"
#include "havescope.h"
int socket_accept6(int s,char* ip,uint16* port,uint32* scope_id)
{
@ -19,7 +23,8 @@ int socket_accept6(int s,char* ip,uint16* port,uint32* scope_id)
int fd;
fd = accept(s,(struct sockaddr *) &sa,&dummy);
if (fd == -1) return -1;
if (fd == -1)
return winsock2errno(-1);
#ifdef LIBC_HAS_IP6
if (sa.sin6_family==AF_INET) {
@ -33,7 +38,11 @@ int socket_accept6(int s,char* ip,uint16* port,uint32* scope_id)
}
if (ip) byte_copy(ip,16,(char *) &sa.sin6_addr);
if (port) uint16_unpack_big((char *) &sa.sin6_port,port);
#ifdef HAVE_SCOPE_ID
if (scope_id) *scope_id=sa.sin6_scope_id;
#else
if (scope_id) *scope_id=0;
#endif
return fd;
#else

@ -1,6 +1,9 @@
#ifndef __MINGW32__
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#endif
#include "windoze.h"
#include "byte.h"
#include "uint16.h"
#include "uint32.h"
@ -15,5 +18,5 @@ int socket_bind4(int s,const char *ip,uint16 port) {
*(uint32*)&si.sin_addr = *(uint32*)ip;
else
si.sin_addr.s_addr=INADDR_ANY;
return bind(s,(struct sockaddr*)&si,sizeof si);
return winsock2errno(bind(s,(struct sockaddr*)&si,sizeof si));
}

@ -1,9 +1,12 @@
#include <sys/types.h>
#ifndef __MINGW32__
#include <sys/socket.h>
#endif
#include "socket.h"
#include "windoze.h"
int socket_bind4_reuse(int s,const char *ip,uint16 port) {
int one=1;
setsockopt(s,SOL_SOCKET,SO_REUSEADDR,&one,sizeof one);
return socket_bind4(s,ip,port);
return winsock2errno(socket_bind4(s,ip,port));
}

@ -1,8 +1,11 @@
#include <errno.h>
#include "haveip6.h"
#include <sys/types.h>
#ifndef __MINGW32__
#include <sys/socket.h>
#include <netinet/in.h>
#endif
#include "windoze.h"
#include "ip6.h"
#include "byte.h"
#include "socket.h"
@ -32,7 +35,7 @@ int socket_bind6(int s,const char ip[16],uint16 port,uint32 scope_id)
byte_copy((char *) &sa.sin6_addr,16,ip);
sa.sin6_scope_id=scope_id;
return bind(s,(struct sockaddr *) &sa,sizeof sa);
return winsock2errno(bind(s,(struct sockaddr *) &sa,sizeof sa));
#else
errno=EPROTONOSUPPORT;
return -1;

@ -1,9 +1,12 @@
#include <sys/types.h>
#ifndef __MINGW32__
#include <sys/socket.h>
#endif
#include "socket.h"
#include "windoze.h"
int socket_bind6_reuse(int s,const char *ip,uint16 port,uint32 scope_id) {
int one=1;
setsockopt(s,SOL_SOCKET,SO_REUSEADDR,&one,sizeof one);
return socket_bind6(s,ip,port,scope_id);
return winsock2errno(socket_bind6(s,ip,port,scope_id));
}

@ -1,12 +1,15 @@
#include <sys/types.h>
#include <sys/param.h>
#ifndef __MINGW32__
#include <sys/socket.h>
#include <netinet/in.h>
#endif
#include "socket.h"
#include "windoze.h"
int socket_broadcast(int s)
{
int opt = 1;
return setsockopt(s,SOL_SOCKET,SO_BROADCAST,&opt,sizeof opt);
return winsock2errno(setsockopt(s,SOL_SOCKET,SO_BROADCAST,&opt,sizeof opt));
}

@ -1,6 +1,9 @@
#include <sys/types.h>
#ifndef __MINGW32__
#include <sys/socket.h>
#include <netinet/in.h>
#endif
#include "windoze.h"
#include "byte.h"
#include "socket.h"
@ -13,5 +16,5 @@ int socket_connect4(int s,const char *ip,uint16 port) {
si.sin_family=AF_INET;
uint16_pack_big((char*) &si.sin_port,port);
*((uint32*)&si.sin_addr) = *((uint32*)ip);
return (connect(s,(struct sockaddr*)&si,sizeof(si)));
return (winsock2errno(connect(s,(struct sockaddr*)&si,sizeof(si))));
}

@ -1,7 +1,10 @@
#include <sys/param.h>
#include <sys/types.h>
#ifndef __MINGW32__
#include <sys/socket.h>
#include <netinet/in.h>
#endif
#include "windoze.h"
#include <errno.h>
#include "byte.h"
#include "socket.h"
@ -9,6 +12,7 @@
#include "haveip6.h"
#include "uint32.h"
#include "ip4.h"
#include "havescope.h"
int socket_connect6(int s,const char ip[16],uint16 port,uint32 scope_id)
{
@ -18,19 +22,21 @@ int socket_connect6(int s,const char ip[16],uint16 port,uint32 scope_id)
if (noipv6) {
#endif
if (ip6_isv4mapped(ip))
return socket_connect4(s,ip+12,port);
return winsock2errno(socket_connect4(s,ip+12,port));
if (byte_equal(ip,16,V6loopback))
return socket_connect4(s,ip4loopback,port);
return winsock2errno(socket_connect4(s,ip4loopback,port));
#ifdef LIBC_HAS_IP6
}
byte_zero(&sa,sizeof sa);
sa.sin6_family = PF_INET6;
uint16_pack_big((char *) &sa.sin6_port,port);
sa.sin6_flowinfo = 0;
#ifdef HAVE_SCOPE_ID
sa.sin6_scope_id = scope_id;
#endif
byte_copy((char *) &sa.sin6_addr,16,ip);
return connect(s,(struct sockaddr *) &sa,sizeof sa);
return winsock2errno(connect(s,(struct sockaddr *) &sa,sizeof sa));
#else
errno=EPROTONOSUPPORT;
return -1;

@ -1,6 +1,8 @@
#include <sys/types.h>
#ifndef __MINGW32__
#include <sys/socket.h>
#include <netinet/in.h>
#endif
#include "socket.h"
#include "havesl.h"

@ -1,6 +1,8 @@
#include <sys/types.h>
#ifndef __MINGW32__
#include <sys/socket.h>
#include <net/if.h>
#endif
#include "socket.h"
#include "haven2i.h"

@ -1,21 +1,23 @@
#include <sys/types.h>
#ifndef __MINGW32__
#include <sys/socket.h>
#include <net/if.h>
#endif
#include "socket.h"
#include "haven2i.h"
#ifdef HAVE_N2I
static char ifname[IFNAMSIZ];
const char* socket_getifname(uint32 interface) {
char *tmp=if_indextoname(interface,ifname);
const char* socket_getifname(uint32 _interface) {
char *tmp=if_indextoname(_interface,ifname);
if (tmp)
return tmp;
else
return "[unknown]";
}
#else
const char* socket_getifname(uint32 interface) {
const char* socket_getifname(uint32 _interface) {
return "[unknown]";
}
#endif

@ -1,6 +1,10 @@
#include <sys/types.h>
#ifndef __MINGW32__
#include <sys/socket.h>
#endif
#include "socket.h"
#include "windoze.h"
int socket_listen(int s,unsigned int backlog) {
return listen(s, backlog);
return winsock2errno(listen(s, backlog));
}

@ -1,7 +1,10 @@
#include <sys/types.h>
#include <sys/param.h>
#ifndef __MINGW32__
#include <sys/socket.h>
#include <netinet/in.h>
#endif
#include "windoze.h"
#include "byte.h"
#include "socket.h"
#include "havesl.h"
@ -11,7 +14,7 @@ int socket_local4(int s,char ip[4],uint16 *port)
struct sockaddr_in si;
socklen_t len = sizeof si;
if (getsockname(s,(struct sockaddr *) &si,&len) == -1) return -1;
if (getsockname(s,(struct sockaddr *) &si,&len) == -1) return winsock2errno(-1);
if (ip) *(uint32*)ip = *(uint32*)&si.sin_addr;
if (port) uint16_unpack_big((char *) &si.sin_port,port);
return 0;

@ -1,13 +1,17 @@
#include <sys/types.h>
#include <sys/param.h>
#ifndef __MINGW32__
#include <sys/socket.h>
#include <netinet/in.h>
#endif
#include "windoze.h"
#include "byte.h"
#include "socket.h"
#include "ip6.h"
#include "haveip6.h"
#include "uint32.h"
#include "havesl.h"
#include "havescope.h"
int socket_local6(int s,char ip[16],uint16 *port,uint32 *scope_id)
{
@ -18,7 +22,7 @@ int socket_local6(int s,char ip[16],uint16 *port,uint32 *scope_id)
#endif
socklen_t len = sizeof si;
if (getsockname(s,(struct sockaddr *) &si,&len) == -1) return -1;
if (getsockname(s,(struct sockaddr *) &si,&len) == -1) return winsock2errno(-1);
#ifdef LIBC_HAS_IP6
if (si.sin6_family==AF_INET) {
struct sockaddr_in *si4=(struct sockaddr_in*)&si;
@ -31,7 +35,12 @@ int socket_local6(int s,char ip[16],uint16 *port,uint32 *scope_id)
}
if (ip) byte_copy(ip,16,(char *) &si.sin6_addr);
if (port) uint16_unpack_big((char *) &si.sin6_port,port);
#ifdef HAVE_SCOPE_ID
if (scope_id) *scope_id=si.sin6_scope_id;
#else
if (scope_id) *scope_id=0;
#endif
#else
if (ip) {
byte_copy(ip,12,V4mappedprefix);

@ -1,7 +1,10 @@
#include <sys/types.h>
#include <sys/param.h>
#ifndef __MINGW32__
#include <sys/socket.h>
#include <netinet/in.h>
#endif
#include "windoze.h"
#include "socket.h"
#include "byte.h"
#include "haveip6.h"
@ -14,8 +17,8 @@
int socket_mchopcount6(int s,char TTL)
{
#ifdef LIBC_HAS_IP6
return setsockopt(s,IPPROTO_IPV6,IPV6_MULTICAST_HOPS,&TTL,sizeof TTL);
return winsock2errno(setsockopt(s,IPPROTO_IPV6,IPV6_MULTICAST_HOPS,&TTL,sizeof TTL));
#else
return socket_mcttl4(s,TTL);
return winsock2errno(socket_mcttl4(s,TTL));
#endif
}

@ -1,15 +1,18 @@
#include <sys/types.h>
#include <sys/param.h>
#ifndef __MINGW32__
#include <sys/socket.h>
#include <netinet/in.h>
#endif
#include "windoze.h"
#include "socket.h"
#include "byte.h"
int socket_mcjoin4(int s,const char ip[4],const char interface[4])
int socket_mcjoin4(int s,const char ip[4],const char _interface[4])
{
struct ip_mreq opt;
byte_copy(&opt.imr_multiaddr.s_addr,4,ip);
byte_copy(&opt.imr_interface.s_addr,4,interface);
return setsockopt(s,IPPROTO_IP,IP_ADD_MEMBERSHIP,&opt,sizeof opt);
byte_copy(&opt.imr_interface.s_addr,4,_interface);
return winsock2errno(setsockopt(s,IPPROTO_IP,IP_ADD_MEMBERSHIP,&opt,sizeof opt));
}

@ -1,7 +1,10 @@
#include <sys/types.h>
#include <sys/param.h>
#ifndef __MINGW32__
#include <sys/socket.h>
#include <netinet/in.h>
#endif
#include "windoze.h"
#include "socket.h"
#include "byte.h"
#include "haveip6.h"
@ -16,7 +19,7 @@
#endif
#endif
int socket_mcjoin6(int s,const char ip[16],int interface)
int socket_mcjoin6(int s,const char ip[16],int _interface)
{
#ifdef LIBC_HAS_IP6
struct ipv6_mreq opt;
@ -25,8 +28,8 @@ int socket_mcjoin6(int s,const char ip[16],int interface)
return socket_mcjoin4(s,ip+12,ip);
#ifdef LIBC_HAS_IP6
byte_copy(&opt.ipv6mr_multiaddr,16,ip);
opt.ipv6mr_interface=interface;
return setsockopt(s,IPPROTO_IPV6,IPV6_ADD_MEMBERSHIP,&opt,sizeof opt);
opt.ipv6mr_interface=_interface;
return winsock2errno(setsockopt(s,IPPROTO_IPV6,IPV6_ADD_MEMBERSHIP,&opt,sizeof opt));
#else
errno=EPROTONOSUPPORT;
return -1;

@ -1,7 +1,10 @@
#include <sys/types.h>
#include <sys/param.h>
#ifndef __MINGW32__
#include <sys/socket.h>
#include <netinet/in.h>
#endif
#include "windoze.h"
#include "socket.h"
#include "byte.h"
@ -10,6 +13,6 @@ int socket_mcleave4(int s,const char ip[4])
struct ip_mreq opt;
byte_copy(&opt.imr_multiaddr.s_addr,4,ip);
byte_zero(&opt.imr_interface.s_addr,4);
return setsockopt(s,IPPROTO_IP,IP_DROP_MEMBERSHIP,&opt,sizeof opt);
return winsock2errno(setsockopt(s,IPPROTO_IP,IP_DROP_MEMBERSHIP,&opt,sizeof opt));
}

@ -1,7 +1,10 @@
#include <sys/types.h>
#include <sys/param.h>
#ifndef __MINGW32__
#include <sys/socket.h>
#include <netinet/in.h>
#endif
#include "windoze.h"
#include "socket.h"
#include "byte.h"
#include "haveip6.h"
@ -26,7 +29,7 @@ int socket_mcleave6(int s,const char ip[16])
#ifdef LIBC_HAS_IP6
byte_copy(&opt.ipv6mr_multiaddr,16,ip);
opt.ipv6mr_interface=0;
return setsockopt(s,IPPROTO_IPV6,IPV6_DROP_MEMBERSHIP,&opt,sizeof opt);
return winsock2errno(setsockopt(s,IPPROTO_IPV6,IPV6_DROP_MEMBERSHIP,&opt,sizeof opt));
#else
errno=EPROTONOSUPPORT;
return -1;

@ -1,11 +1,14 @@
#include <sys/types.h>
#include <sys/param.h>
#ifndef __MINGW32__
#include <sys/socket.h>
#include <netinet/in.h>
#endif
#include "windoze.h"
#include "socket.h"
int socket_mcloop4(int s,char loop)
{
return setsockopt(s,IPPROTO_IP,IP_MULTICAST_LOOP,&loop,sizeof loop);
return winsock2errno(setsockopt(s,IPPROTO_IP,IP_MULTICAST_LOOP,&loop,sizeof loop));
}

@ -1,7 +1,10 @@
#include <sys/types.h>
#include <sys/param.h>
#ifndef __MINGW32__
#include <sys/socket.h>
#include <netinet/in.h>
#endif
#include "windoze.h"
#include "socket.h"
#include "haveip6.h"
@ -9,11 +12,11 @@ int socket_mcloop6(int s,char loop)
{
#ifdef LIBC_HAS_IP6
if (noipv6)
return setsockopt(s,IPPROTO_IP,IP_MULTICAST_LOOP,&loop,sizeof loop);
return winsock2errno(setsockopt(s,IPPROTO_IP,IP_MULTICAST_LOOP,&loop,sizeof loop));
else
return setsockopt(s,IPPROTO_IPV6,IPV6_MULTICAST_LOOP,&loop,sizeof loop);
return winsock2errno(setsockopt(s,IPPROTO_IPV6,IPV6_MULTICAST_LOOP,&loop,sizeof loop));
#else
return setsockopt(s,IPPROTO_IP,IP_MULTICAST_LOOP,&loop,sizeof loop);
return winsock2errno(setsockopt(s,IPPROTO_IP,IP_MULTICAST_LOOP,&loop,sizeof loop));
#endif
}

@ -1,11 +1,14 @@
#include <sys/types.h>
#include <sys/param.h>
#ifndef __MINGW32__
#include <sys/socket.h>
#include <netinet/in.h>
#endif
#include "windoze.h"
#include "socket.h"
int socket_mcttl4(int s,char TTL)
{
return setsockopt(s,IPPROTO_IP,IP_MULTICAST_TTL,&TTL,sizeof TTL);
return winsock2errno(setsockopt(s,IPPROTO_IP,IP_MULTICAST_TTL,&TTL,sizeof TTL));
}

@ -1,7 +1,10 @@
#include <sys/types.h>
#include <sys/param.h>
#ifndef __MINGW32__
#include <sys/socket.h>
#include <netinet/in.h>
#endif
#include "windoze.h"
#include "socket.h"
#include "havesl.h"
@ -10,7 +13,7 @@ int socket_recv4(int s,char *buf,unsigned int len,char ip[4],uint16 *port) {
socklen_t Len = sizeof si;
int r;
if ((r = recvfrom(s,buf,len,0,(struct sockaddr *) &si,&Len))<0) return -1;
if ((r = recvfrom(s,buf,len,0,(struct sockaddr *) &si,&Len))<0) return winsock2errno(-1);
if (ip) *(uint32*)ip = *(uint32*)&si.sin_addr;
if (port) uint16_unpack_big((char *) &si.sin_port,port);
return r;

@ -1,12 +1,16 @@
#include <sys/param.h>
#include <sys/types.h>
#ifndef __MINGW32__
#include <sys/socket.h>
#include <netinet/in.h>
#endif
#include "windoze.h"
#include "byte.h"
#include "socket.h"
#include "ip6.h"
#include "haveip6.h"
#include "havesl.h"
#include "havescope.h"
int socket_recv6(int s,char *buf,unsigned int len,char ip[16],uint16 *port,uint32 *scope_id)
{
@ -19,7 +23,7 @@ int socket_recv6(int s,char *buf,unsigned int len,char ip[16],uint16 *port,uint3
int r;
byte_zero(&si,Len);
if ((r = recvfrom(s,buf,len,0,(struct sockaddr *) &si,&Len))<0) return -1;
if ((r = recvfrom(s,buf,len,0,(struct sockaddr *) &si,&Len))<0) return winsock2errno(-1);
#ifdef LIBC_HAS_IP6
if (noipv6) {
@ -33,7 +37,11 @@ int socket_recv6(int s,char *buf,unsigned int len,char ip[16],uint16 *port,uint3
}
if (ip) byte_copy(ip,16,(char *) &si.sin6_addr);
if (port) uint16_unpack_big((char *) &si.sin6_port,port);
#ifdef HAVE_SCOPE_ID
if (scope_id) *scope_id=si.sin6_scope_id;
#else
if (scope_id) *scope_id=0;
#endif
#else
if (ip) {
byte_copy(ip,12,(char *)V4mappedprefix);

@ -1,17 +1,21 @@
#include <sys/types.h>
#include <sys/param.h>
#ifndef __MINGW32__
#include <sys/socket.h>
#include <netinet/in.h>
#endif
#include "windoze.h"
#include "byte.h"
#include "socket.h"
#include "havesl.h"
#include "havescope.h"
int socket_remote4(int s,char ip[4],uint16 *port)
{
struct sockaddr_in si;
socklen_t len = sizeof si;
if (getpeername(s,(struct sockaddr *) &si,&len) == -1) return -1;
if (getpeername(s,(struct sockaddr *) &si,&len) == -1) return winsock2errno(-1);
if (ip) *(uint32*)ip = *(uint32*)&si.sin_addr;
if (port) uint16_unpack_big((char *) &si.sin_port,port);
return 0;

@ -1,13 +1,17 @@
#include <sys/types.h>
#include <sys/param.h>
#ifndef __MINGW32__
#include <sys/socket.h>
#include <netinet/in.h>
#endif
#include "windoze.h"
#include "byte.h"
#include "socket.h"
#include "ip6.h"
#include "haveip6.h"
#include "uint32.h"
#include "havesl.h"
#include "havescope.h"
int socket_remote6(int s,char ip[16],uint16 *port,uint32 *scope_id)
{
@ -18,7 +22,7 @@ int socket_remote6(int s,char ip[16],uint16 *port,uint32 *scope_id)
#endif
socklen_t len = sizeof si;
if (getpeername(s,(struct sockaddr *) &si,&len) == -1) return -1;
if (getpeername(s,(struct sockaddr *) &si,&len) == -1) return winsock2errno(-1);
#ifdef LIBC_HAS_IP6
if (si.sin6_family==AF_INET) {
struct sockaddr_in *si4=(struct sockaddr_in*)&si;
@ -31,7 +35,11 @@ int socket_remote6(int s,char ip[16],uint16 *port,uint32 *scope_id)
}
if (ip) byte_copy(ip,16,(char *) &si.sin6_addr);
if (port) uint16_unpack_big((char *) &si.sin6_port,port);
#ifdef HAVE_SCOPE_ID
if (scope_id) *scope_id=si.sin6_scope_id;
#else
if (scope_id) *scope_id=0;
#endif
#else
if (ip) {
byte_copy(ip,12,V4mappedprefix);

@ -1,7 +1,10 @@
#include <sys/types.h>
#include <sys/param.h>
#ifndef __MINGW32__
#include <sys/socket.h>
#include <netinet/in.h>
#endif
#include "windoze.h"
#include "byte.h"
#include "socket.h"
@ -12,5 +15,5 @@ int socket_send4(int s,const char *buf,unsigned int len,const char ip[4],uint16
si.sin_family = AF_INET;
uint16_pack_big((char*) &si.sin_port,port);
*((uint32*)&si.sin_addr) = *((uint32*)ip);
return sendto(s,buf,len,0,(struct sockaddr *) &si,sizeof si);
return winsock2errno(sendto(s,buf,len,0,(struct sockaddr *) &si,sizeof si));
}

@ -1,13 +1,17 @@
#include <sys/types.h>
#include <sys/param.h>
#ifndef __MINGW32__
#include <sys/socket.h>
#include <netinet/in.h>
#endif
#include "windoze.h"
#include <errno.h>
#include "byte.h"
#include "socket.h"
#include "ip6.h"
#include "haveip6.h"
#include "ip4.h"
#include "havescope.h"
int socket_send6(int s,const char *buf,unsigned int len,const char ip[16],uint16 port,uint32 scope_id)
{
@ -32,7 +36,12 @@ int socket_send6(int s,const char *buf,unsigned int len,const char ip[16],uint16
si.sin6_family = AF_INET6;
uint16_pack_big((char *) &si.sin6_port,port);
byte_copy((char *) &si.sin6_addr,16,ip);
return sendto(s,buf,len,0,(struct sockaddr *) &si,sizeof si);
#ifdef HAVE_SCOPE_ID
si.sin6_scope_id=scope_id;
#else
si.sin6_scope_id=0;
#endif
return winsock2errno(sendto(s,buf,len,0,(struct sockaddr *) &si,sizeof si));
#else
errno=EPROTONOSUPPORT;
return -1;

@ -1,9 +1,12 @@
#include <sys/types.h>
#ifndef __MINGW32__
#include <sys/socket.h>
#include <netinet/in.h>
#endif
#include "windoze.h"
#include "socket.h"
int socket_tcp4(void) {
return socket(PF_INET,SOCK_STREAM,IPPROTO_TCP);
__winsock_init();
return winsock2errno(socket(PF_INET,SOCK_STREAM,IPPROTO_TCP));
}

@ -1,6 +1,9 @@
#include <sys/types.h>
#ifndef __MINGW32__
#include <sys/socket.h>
#include <netinet/in.h>
#endif
#include "windoze.h"
#include <errno.h>
#include "haveip6.h"
#include "socket.h"
@ -14,8 +17,9 @@ int socket_tcp6(void)
#ifdef LIBC_HAS_IP6
int s;
__winsock_init();
if (noipv6) goto compat;
s = socket(PF_INET6,SOCK_STREAM,0);
s = winsock2errno(socket(PF_INET6,SOCK_STREAM,0));
if (s == -1) {
if (errno == EINVAL || errno == EAFNOSUPPORT) {
compat:
@ -28,7 +32,7 @@ compat:
#ifdef IPV6_V6ONLY
{
int zero=0;
setsockopt(s,IPPROTO_IPV6,IPV6_V6ONLY,(void*)&zero,sizeof(zero));
winsock2errno(setsockopt(s,IPPROTO_IPV6,IPV6_V6ONLY,(void*)&zero,sizeof(zero)));
}
#endif
return s;

@ -1,11 +1,14 @@
#include <sys/types.h>
#ifndef __MINGW32__
#include <sys/socket.h>
#endif
#include "windoze.h"
#include "socket.h"
void socket_tryreservein(int s,int size)
{
while (size >= 1024) {
if (setsockopt(s,SOL_SOCKET,SO_RCVBUF,&size,sizeof size) == 0) return;
if (winsock2errno(setsockopt(s,SOL_SOCKET,SO_RCVBUF,&size,sizeof size)) == 0) return;
size -= (size >> 5);
}
}

@ -1,9 +1,13 @@
#include <sys/types.h>
#ifndef __MINGW32__
#include <sys/socket.h>
#include <netinet/in.h>
#endif
#include "windoze.h"
#include "socket.h"
int socket_udp4(void) {
return socket(PF_INET,SOCK_DGRAM,IPPROTO_UDP);
__winsock_init();
return winsock2errno(socket(PF_INET,SOCK_DGRAM,IPPROTO_UDP));
}

@ -1,6 +1,9 @@
#include <sys/types.h>
#ifndef __MINGW32__
#include <sys/socket.h>
#include <netinet/in.h>
#endif
#include "windoze.h"
#include <errno.h>
#include "haveip6.h"
#include "socket.h"
@ -14,12 +17,13 @@ int socket_udp6(void)
#ifdef LIBC_HAS_IP6
int s;
__winsock_init();
if (noipv6) goto compat;
s = socket(PF_INET6,SOCK_DGRAM,0);
s = winsock2errno(socket(PF_INET6,SOCK_DGRAM,0));
if (s == -1) {
if (errno == EINVAL || errno == EAFNOSUPPORT) {
compat:
s=socket(AF_INET,SOCK_DGRAM,0);
s=winsock2errno(socket(AF_INET,SOCK_DGRAM,0));
noipv6=1;
if (s==-1) return -1;
} else
@ -28,7 +32,7 @@ compat:
#ifdef IPV6_V6ONLY
{
int zero=0;
setsockopt(s,IPPROTO_IPV6,IPV6_V6ONLY,(void*)&zero,sizeof(zero));
winsock2errno(setsockopt(s,IPPROTO_IPV6,IPV6_V6ONLY,(void*)&zero,sizeof(zero)));
}
#endif
return s;

@ -1,12 +1,29 @@
#include <sys/types.h>
#include <sys/time.h>
#include "taia.h"
#ifdef __MINGW32__
#include <windows.h>
#endif
void taia_now(struct taia *t)
{
#ifdef __MINGW32__
union {
FILETIME f;
unsigned long long l;
} fnord;
GetSystemTimeAsFileTime(&fnord.f);
/* 64-bit value representing the number of 100-nanosecond intervals
* since January 1, 1601 (UTC) */
fnord.l-=((long long)(1970-1601))*365*24*60*60;
t->sec.x=fnord.l/10000000;
t->nano=((fnord.l+5)/10)%1000000;
t->atto=0;
#else
struct timeval now;
gettimeofday(&now,(struct timezone *) 0);
tai_unix(&t->sec,now.tv_sec);
t->nano = 1000 * now.tv_usec + 500;
t->atto = 0;
#endif
}

@ -0,0 +1,28 @@
#include <stdio.h>
#include <stdlib.h>
#include <poll.h>
#include <netdb.h>
#include <unistd.h>
#include <fcntl.h>
#include <strings.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/errno.h>
#include <netinet/in.h>
#include <sys/devpoll.h>
main() {
int fd=open("/dev/poll",O_RDWR);
struct pollfd p[100];
int i,r;
dvpoll_t timeout;
p[0].fd=0;
p[0].events=POLLIN;
write(fd,p,sizeof(struct pollfd));
timeout.dp_timeout=100; /* milliseconds? */
timeout.dp_nfds=1;
timeout.dp_fds=p;
r=ioctl(fd,DP_POLL,&timeout);
for (i=0; i<r; ++i)
printf("event %d on fd #%d\n",p[i].revents,p[i].fd);
}

@ -0,0 +1,9 @@
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
main() {
struct sockaddr_in6 sa;
sa.sin6_family = PF_INET6;
sa.sin6_scope_id = 23;
}

@ -1,6 +1,11 @@
#include <sys/types.h>
#ifdef __MINGW32__
#include <winsock2.h>
#include <ws2tcpip.h>
#else
#include <sys/socket.h>
#include <netinet/in.h>
#endif
main() {
socklen_t t;

@ -1,6 +1,10 @@
#include "taia.h"
#include "select.h"
#include "iopause.h"
#ifdef __MINGW32__
#include <winsock2.h>
#else
#include "select.h"
#endif
void iopause(iopause_fd *x,unsigned int len,struct taia *deadline,struct taia *stamp)
{

@ -3,10 +3,20 @@
#include "ndelay.h"
#ifdef __MINGW32__
#include <winsock2.h>
#include "windoze.h"
#endif
#ifndef O_NDELAY
#define O_NDELAY O_NONBLOCK
#endif
int ndelay_off(int fd) {
#ifdef __MINGW32__
unsigned long i=1;
return winsock2errno(ioctlsocket( fd, FIONBIO, &i));
#else
return fcntl(fd,F_SETFL,fcntl(fd,F_GETFL,0) & ~O_NDELAY);
#endif
}

@ -3,10 +3,20 @@
#include "ndelay.h"
#ifdef __MINGW32__
#include <winsock2.h>
#include "windoze.h"
#endif
#ifndef O_NDELAY
#define O_NDELAY O_NONBLOCK
#endif
int ndelay_on(int fd) {
#ifdef __MINGW32__
unsigned long i=0;
return winsock2errno(ioctlsocket( fd, FIONBIO, &i));
#else
return fcntl(fd,F_SETFL,fcntl(fd,F_GETFL,0) | O_NDELAY);
#endif
}

Loading…
Cancel
Save