#include "services.h"
Go to the source code of this file.
Functions | |
| int32 | read_buffer_len () |
| static int | buffered_read (ano_socket_t fd, char *buf, int len) |
| static int | buffered_read_one (ano_socket_t fd) |
| int32 | write_buffer_len () |
| static int | flush_write_buffer (int wait) |
| static int | buffered_write (ano_socket_t fd, char *buf, int len) |
| int | sgetc (ano_socket_t s) |
| int | sungetc (int c, int s) |
| char * | sgets (char *buf, int len, ano_socket_t s) |
| char * | sgets2 (char *buf, int len, ano_socket_t s) |
| int | sread (ano_socket_t s, char *buf, int len) |
| int | sputs (char *str, ano_socket_t s) |
| int | sockprintf (ano_socket_t s, char *fmt,...) |
| static char * | pack_ip (const char *ipaddr) |
| int | conn (const char *host, int port, const char *lhost, int lport) |
| void | disconn (ano_socket_t s) |
Variables | |
| static char | read_netbuf [NET_BUFSIZE] |
| static char * | read_curpos = read_netbuf |
| static char * | read_bufend = read_netbuf |
| static char *const | read_buftop = read_netbuf + NET_BUFSIZE |
| int32 | total_read = 0 |
| static char | write_netbuf [NET_BUFSIZE] |
| static char * | write_curpos = write_netbuf |
| static char * | write_bufend = write_netbuf |
| static char *const | write_buftop = write_netbuf + NET_BUFSIZE |
| static int | write_fd = -1 |
| int32 | total_written |
| static int | lastchar = EOF |
| static int buffered_read | ( | ano_socket_t | fd, | |
| char * | buf, | |||
| int | len | |||
| ) | [static] |
Read data.
| fd | File Pointer | |
| buf | Buffer | |
| int | Length of buffer |
Definition at line 56 of file sockutil.c.
References alog(), ano_sockgeterr, ano_sockread, ano_sockseterr, debug, read_bufend, read_buftop, read_curpos, read_netbuf, SOCKERR_EBADF, and total_read.
Referenced by sread().
| static int buffered_read_one | ( | ano_socket_t | fd | ) | [static] |
Optimized version of the above for reading a single character; returns the character in an int or EOF, like fgetc().
| fd | File Pointer |
Definition at line 133 of file sockutil.c.
References alog(), ano_sockgeterr, ano_sockread, ano_sockseterr, c, debug, read_bufend, read_buftop, read_curpos, read_netbuf, SOCKERR_EBADF, and total_read.
Referenced by sgetc().
| static int buffered_write | ( | ano_socket_t | fd, | |
| char * | buf, | |||
| int | len | |||
| ) | [static] |
Write data.
| fd | File Pointer | |
| buf | Buffer to write | |
| len | Length to write |
Definition at line 253 of file sockutil.c.
References alog(), ano_sockgeterr, ano_sockseterr, debug, flush_write_buffer(), write_bufend, write_buftop, write_curpos, write_fd, and write_netbuf.
Referenced by sockprintf(), and sputs().
| int conn | ( | const char * | host, | |
| int | port, | |||
| const char * | lhost, | |||
| int | lport | |||
| ) |
lhost/lport specify the local side of the connection. If they are not given (lhost==NULL, lport==0), then they are left free to vary.
| host | Remote Host | |
| port | Remote Port | |
| lhost | LocalHost | |
| lport | LocalPort |
Definition at line 553 of file sockutil.c.
References alog(), ano_sockclose, ano_sockgeterr, ano_sockseterr, pack_ip(), and SOCKERR_EINVAL.
Referenced by init_secondary().
| void disconn | ( | ano_socket_t | s | ) |
Close up the connection
| s | Socket |
Definition at line 632 of file sockutil.c.
References ano_sockclose.
Referenced by init_secondary(), main(), services_restart(), and services_shutdown().
| static int flush_write_buffer | ( | int | wait | ) | [static] |
Helper routine to try and write up to one chunk of data from the buffer to the socket. Return how much was written.
| wait | Wait |
Definition at line 209 of file sockutil.c.
References alog(), ano_sockgeterr, ano_sockseterr, ano_sockwrite, debug, total_written, write_bufend, write_buftop, write_curpos, write_fd, and write_netbuf.
Referenced by buffered_write(), and sgets().
| static char* pack_ip | ( | const char * | ipaddr | ) | [static] |
Translate an IP dotted-quad address to a 4-byte character string. Return NULL if the given string is not in dotted-quad format.
| ipaddr | IP Address |
Definition at line 524 of file sockutil.c.
Referenced by conn().
| int32 read_buffer_len | ( | void | ) |
Return amount of data in read buffer.
Definition at line 38 of file sockutil.c.
References NET_BUFSIZE, read_bufend, and read_curpos.
| int sgetc | ( | ano_socket_t | s | ) |
Optimized version of the above for writing a single character; returns the character in an int or EOF, like fputc(). Commented out because it isn't currently used.
| int | to write | |
| fd | Pointer |
| int | to read |
Definition at line 376 of file sockutil.c.
References buffered_read_one(), and lastchar.
Referenced by sgets().
| char* sgets | ( | char * | buf, | |
| int | len, | |||
| ano_socket_t | s | |||
| ) |
If connection was broken, return NULL. If the read timed out, return (char *)-1.
| buf | Buffer to get | |
| len | Length | |
| s | Socket |
Definition at line 411 of file sockutil.c.
References ano_sockgeterr, flush_write_buffer(), read_buffer_len(), ReadTimeout, and sgetc().
Referenced by sgets2().
| char* sgets2 | ( | char * | buf, | |
| int | len, | |||
| ano_socket_t | s | |||
| ) |
sgets2: Read a line of text from a socket, and strip newline and carriage return characters from the end of the line.
| buf | Buffer to get | |
| len | Length | |
| s | Socket |
Definition at line 451 of file sockutil.c.
References sgets().
Referenced by init_secondary(), and main().
| int sockprintf | ( | ano_socket_t | s, | |
| char * | fmt, | |||
| ... | ||||
| ) |
sockprintf : a socket writting printf()
| s | Socket | |
| fmt | format of message | |
| ... | various args |
Definition at line 502 of file sockutil.c.
References buffered_write(), and vsnprintf.
Referenced by vsend_cmd().
| int sputs | ( | char * | str, | |
| ano_socket_t | s | |||
| ) |
sputs : write buffer
| s | Socket | |
| str | Buffer to write |
Definition at line 488 of file sockutil.c.
References buffered_write().
| int sread | ( | ano_socket_t | s, | |
| char * | buf, | |||
| int | len | |||
| ) |
Read from a socket. (Use this instead of read() because it has buffering.)
| s | Socket | |
| buf | Buffer to get | |
| len | Length |
Definition at line 475 of file sockutil.c.
References buffered_read().
| int sungetc | ( | int | c, | |
| int | s | |||
| ) |
sungetc ?
| int | c | |
| int | s |
Definition at line 396 of file sockutil.c.
References lastchar.
| int32 write_buffer_len | ( | void | ) |
Return amount of data in write buffer.
Definition at line 192 of file sockutil.c.
References NET_BUFSIZE, write_bufend, and write_curpos.
Referenced by m_stats().
int lastchar = EOF [static] |
char* read_bufend = read_netbuf [static] |
Definition at line 21 of file sockutil.c.
Referenced by buffered_read(), buffered_read_one(), and read_buffer_len().
char* const read_buftop = read_netbuf + NET_BUFSIZE [static] |
char* read_curpos = read_netbuf [static] |
Definition at line 20 of file sockutil.c.
Referenced by buffered_read(), buffered_read_one(), and read_buffer_len().
char read_netbuf[NET_BUFSIZE] [static] |
| int32 total_read = 0 |
Definition at line 23 of file sockutil.c.
Definition at line 29 of file sockutil.c.
char* write_bufend = write_netbuf [static] |
Definition at line 26 of file sockutil.c.
Referenced by buffered_write(), flush_write_buffer(), and write_buffer_len().
char* const write_buftop = write_netbuf + NET_BUFSIZE [static] |
char* write_curpos = write_netbuf [static] |
Definition at line 25 of file sockutil.c.
Referenced by buffered_write(), flush_write_buffer(), and write_buffer_len().
int write_fd = -1 [static] |
char write_netbuf[NET_BUFSIZE] [static] |
1.5.7.1