#ifndef __SOCKET_IO_H__
|
#define __SOCKET_IO_H__
|
|
#include "usg_common.h"
|
|
/* Simplifies calls to bind(), connect(), and accept() */
|
/* $begin sockaddrdef */
|
typedef struct sockaddr SA;
|
/* $end sockaddrdef */
|
|
/* Persistent state for the robust I/O (Rio) package */
|
/* $begin rio_t */
|
#define RIO_BUFSIZE 8192
|
#define LISTENQ 1024 /* Second argument to listen() */
|
typedef struct {
|
int rio_fd; /* Descriptor for this internal buf */
|
int rio_cnt; /* Unread bytes in internal buf */
|
char *rio_bufptr; /* Next unread byte in internal buf */
|
char rio_buf[RIO_BUFSIZE]; /* Internal buffer */
|
} rio_t;
|
/* Rio (Robust I/O) package */
|
ssize_t rio_readn(int fd, void *usrbuf, size_t n);
|
ssize_t rio_writen(int fd, const void *usrbuf, size_t n);
|
void rio_readinitb(rio_t *rp, int fd);
|
ssize_t rio_readnb(rio_t *rp, void *usrbuf, size_t n);
|
ssize_t rio_readlineb(rio_t *rp, char *usrbuf, size_t maxlen);
|
|
/* Wrappers for Rio package */
|
ssize_t Rio_readn(int fd, void *usrbuf, size_t n);
|
void Rio_writen(int fd, const void *usrbuf, size_t n);
|
void Rio_readinitb(rio_t *rp, int fd);
|
ssize_t Rio_readnb(rio_t *rp, void *usrbuf, size_t n);
|
ssize_t Rio_readlineb(rio_t *rp, char *usrbuf, size_t maxlen);
|
|
/* Reentrant protocol-independent client/server helpers */
|
int open_clientfd(const char *hostname, const char *port);
|
int open_listenfd(const char *port);
|
|
/* Wrappers for reentrant protocol-independent client/server helpers */
|
int Open_clientfd(const char *hostname, const char *port);
|
int Open_listenfd(const char *port);
|
void Close(int fd);
|
#endif
|