Moved the safe_write() and safe_read() functions here.
This commit is contained in:
parent
08baf6b01b
commit
b9c4c480d2
32
src/sock.c
32
src/sock.c
@ -1,4 +1,4 @@
|
|||||||
/* $Id: sock.c,v 1.7 2001-09-07 04:18:26 rjkaes Exp $
|
/* $Id: sock.c,v 1.8 2001-09-16 20:11:07 rjkaes Exp $
|
||||||
*
|
*
|
||||||
* Sockets are created and destroyed here. When a new connection comes in from
|
* Sockets are created and destroyed here. When a new connection comes in from
|
||||||
* a client, we need to copy the socket and the create a second socket to the
|
* a client, we need to copy the socket and the create a second socket to the
|
||||||
@ -199,6 +199,36 @@ char *getpeer_string(int fd, char *string)
|
|||||||
return string;
|
return string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Write the buffer to the socket. If an EINTR occurs, pick up and try
|
||||||
|
* again.
|
||||||
|
*/
|
||||||
|
ssize_t safe_write(int fd, const void *buffer, size_t count)
|
||||||
|
{
|
||||||
|
ssize_t len;
|
||||||
|
|
||||||
|
do {
|
||||||
|
len = write(fd, buffer, count);
|
||||||
|
} while (len < 0 && errno == EINTR);
|
||||||
|
|
||||||
|
return len;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Matched pair for safe_write(). If an EINTR occurs, pick up and try
|
||||||
|
* again.
|
||||||
|
*/
|
||||||
|
ssize_t safe_read(int fd, void *buffer, size_t count)
|
||||||
|
{
|
||||||
|
ssize_t len;
|
||||||
|
|
||||||
|
do {
|
||||||
|
len = read(fd, buffer, count);
|
||||||
|
} while (len < 0 && errno == EINTR);
|
||||||
|
|
||||||
|
return len;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Reads in a line of text one character at a time. Finishes when either a
|
* Reads in a line of text one character at a time. Finishes when either a
|
||||||
* newline is detected, or maxlen characters have been read. The function
|
* newline is detected, or maxlen characters have been read. The function
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
/* $Id: sock.h,v 1.4 2001-06-02 02:07:34 rjkaes Exp $
|
/* $Id: sock.h,v 1.5 2001-09-16 20:11:07 rjkaes Exp $
|
||||||
*
|
*
|
||||||
* See 'sock.c' for a detailed description.
|
* See 'sock.c' for a detailed description.
|
||||||
*
|
*
|
||||||
@ -37,6 +37,9 @@ extern int socket_blocking(int sock);
|
|||||||
extern char *getpeer_ip(int fd, char *ipaddr);
|
extern char *getpeer_ip(int fd, char *ipaddr);
|
||||||
extern char *getpeer_string(int fd, char *string);
|
extern char *getpeer_string(int fd, char *string);
|
||||||
|
|
||||||
|
extern ssize_t safe_write(int fd, const void *buffer, size_t count);
|
||||||
|
extern ssize_t safe_read(int fd, void *buffer, size_t count);
|
||||||
|
|
||||||
extern ssize_t readline(int fd, char *ptr, size_t maxlen);
|
extern ssize_t readline(int fd, char *ptr, size_t maxlen);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user