From: Fredrik Tolf Date: Sat, 15 Mar 2008 16:46:15 +0000 (+0100) Subject: New socket API draft. X-Git-Tag: 1.3~31 X-Git-Url: http://git.dolda2000.com/gitweb/?a=commitdiff_plain;h=2b9a1911defbd6f0295b74cd7b41a2a5328d9e6a;p=doldaconnect.git New socket API draft. --- diff --git a/daemon/net.h b/daemon/net.h index 2e7e2d9..23275b3 100644 --- a/daemon/net.h +++ b/daemon/net.h @@ -22,10 +22,9 @@ #include #include -#define SOCK_LST 0 /* Listening */ -#define SOCK_SYN 1 /* Connecting */ -#define SOCK_EST 2 /* Established */ -#define SOCK_STL 3 /* Stale, dead */ +#define SOCK_SYN 0 /* Connecting */ +#define SOCK_EST 1 /* Established */ +#define SOCK_STL 2 /* Stale, dead */ #define SOCK_TOS_MINDELAY 4 #define SOCK_TOS_MAXTP 3 #define SOCK_TOS_MAXREL 2 @@ -42,37 +41,10 @@ struct dgrambuf struct socket { - struct socket *next, *prev; int refcount; - int fd; - int isrealsocket; /* Bleh... */ - int family; - int tos; - int type; int state; - int ignread; - int events; - int close; - struct sockaddr *remote; - socklen_t remotelen; - struct - { - uid_t uid; - gid_t gid; - } ucred; - union - { - struct - { - struct dgrambuf *f, *l; - } d; - struct - { - void *buf; - size_t bufsize; - size_t datasize; - } s; - } outbuf; + int block; + int dgram; union { struct @@ -85,39 +57,53 @@ struct socket size_t bufsize; size_t datasize; } s; - } inbuf; + } buf; void (*conncb)(struct socket *sk, int err, void *data); void (*errcb)(struct socket *sk, int err, void *data); void (*readcb)(struct socket *sk, void *data); void (*writecb)(struct socket *sk, void *data); - void (*acceptcb)(struct socket *sk, struct socket *newsk, void *data); + struct ufd *ufd; + void *data; +}; + +struct lport { + struct ufd *ufd; + void (*acceptcb)(struct lport *lp, struct socket *newsk, void *data); + void (*errcb)(struct lport *lp, int err, void *data); + void (*close)(struct lport *lp); void *data; }; void putsock(struct socket *sk); void getsock(struct socket *sk); -struct socket *netcslisten(int type, struct sockaddr *name, socklen_t namelen, void (*func)(struct socket *, struct socket *, void *), void *data); -struct socket *netcslistenlocal(int type, struct sockaddr *name, socklen_t namelen, void (*func)(struct socket *, struct socket *, void *), void *data); -struct socket *netcstcplisten(int port, int local, void (*func)(struct socket *, struct socket *, void *), void *data); +struct lport *netcslisten(int type, struct sockaddr *name, socklen_t namelen, void (*func)(struct socket *, struct socket *, void *), void *data); +struct lport *netcslistenlocal(int type, struct sockaddr *name, socklen_t namelen, void (*func)(struct socket *, struct socket *, void *), void *data); +struct lport *netcstcplisten(int port, int local, void (*func)(struct socket *, struct socket *, void *), void *data); struct socket *netcsconn(struct sockaddr *addr, socklen_t addrlen, void (*func)(struct socket *, int, void *), void *data); int pollsocks(int timeout); void sockqueue(struct socket *sk, void *data, size_t size); size_t sockqueuesize(struct socket *sk); int netresolve(char *addr, void (*callback)(struct sockaddr *addr, int addrlen, void *data), void *data); struct socket *netcsdgram(struct sockaddr *name, socklen_t namelen); -struct socket *netdupsock(struct socket *sk); -void netdgramconn(struct socket *sk, struct sockaddr *addr, socklen_t addrlen); +struct socket *netdgramconn(struct socket *sk, struct sockaddr *addr, socklen_t addrlen); int sockgetlocalname(struct socket *sk, struct sockaddr **namebuf, socklen_t *lenbuf); int sockgetremotename(struct socket *sk, struct sockaddr **namebuf, socklen_t *lenbuf); int sockgetremotename2(struct socket *sk, struct socket *sk2, struct sockaddr **namebuf, socklen_t *lenbuf); +int getremotename(struct lport *lp, struct sockaddr **namebuf, socklen_t *lenbuf); +int getremotename2(struct lport *lp, struct socket *sk, struct sockaddr **namebuf, socklen_t *lenbuf); void closesock(struct socket *sk); +void closelport(struct lport *lp); void *sockgetinbuf(struct socket *sk, size_t *size); struct socket *wrapsock(int fd); size_t sockgetdatalen(struct socket *sk); -int getpublicaddr(int af, struct sockaddr **addr, socklen_t *lenbuf); int socksettos(struct socket *sk, int tos); int addreq(struct sockaddr *x, struct sockaddr *y); char *formataddress(struct sockaddr *arg, socklen_t arglen); +char *formatsockpeer(struct socket *sk); void sockpushdata(struct socket *sk, void *buf, size_t size); +void sockblock(struct socket *sk, int block); +int sockpeeraddr(struct socket *sk, struct sockaddr **namebuf, socklen_t *lenbuf); +int getucred(struct socket *sk, uid_t *uid, gid_t *gid); +int sockfamily(struct socket *sk); #endif