sockutil.c File Reference

#include "services.h"

Include dependency graph for sockutil.c:

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


Function Documentation

static int buffered_read ( ano_socket_t  fd,
char *  buf,
int  len 
) [static]

Read data.

Parameters:
fd File Pointer
buf Buffer
int Length of buffer
Returns:
int

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().

Parameters:
fd File Pointer
Returns:
int

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.

Parameters:
fd File Pointer
buf Buffer to write
len Length to write
Returns:
int

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.

Parameters:
host Remote Host
port Remote Port
lhost LocalHost
lport LocalPort
Returns:
int if successful

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

Parameters:
s Socket
Returns:
void

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.

Parameters:
wait Wait
Returns:
int

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.

Parameters:
ipaddr IP Address
Returns:
char 4byte ip char string

Definition at line 524 of file sockutil.c.

Referenced by conn().

int32 read_buffer_len ( void   ) 

Return amount of data in read buffer.

Returns:
int32

Definition at line 38 of file sockutil.c.

References NET_BUFSIZE, read_bufend, and read_curpos.

Referenced by m_stats(), and sgets().

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.

Parameters:
int to write
fd Pointer
Returns:
int sgetc ?
Parameters:
int to read
Returns:
int

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.

Parameters:
buf Buffer to get
len Length
s Socket
Returns:
buffer

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.

Parameters:
buf Buffer to get
len Length
s Socket
Returns:
buffer

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()

Parameters:
s Socket
fmt format of message
... various args
Returns:
int

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

Parameters:
s Socket
str Buffer to write
Returns:
int

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.)

Parameters:
s Socket
buf Buffer to get
len Length
Returns:
int

Definition at line 475 of file sockutil.c.

References buffered_read().

int sungetc ( int  c,
int  s 
)

sungetc ?

Parameters:
int c
int s
Returns:
int

Definition at line 396 of file sockutil.c.

References lastchar.

int32 write_buffer_len ( void   ) 

Return amount of data in write buffer.

Returns:
int

Definition at line 192 of file sockutil.c.

References NET_BUFSIZE, write_bufend, and write_curpos.

Referenced by m_stats().


Variable Documentation

int lastchar = EOF [static]

Definition at line 30 of file sockutil.c.

Referenced by sgetc(), and sungetc().

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]

Definition at line 22 of file sockutil.c.

Referenced by buffered_read(), and buffered_read_one().

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]

Definition at line 19 of file sockutil.c.

Referenced by buffered_read(), and buffered_read_one().

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]

Definition at line 27 of file sockutil.c.

Referenced by buffered_write(), and flush_write_buffer().

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]

Definition at line 28 of file sockutil.c.

Referenced by buffered_write(), and flush_write_buffer().

char write_netbuf[NET_BUFSIZE] [static]

Definition at line 24 of file sockutil.c.

Referenced by buffered_write(), and flush_write_buffer().


Generated on Sun Oct 5 09:07:11 2008 for Anope by  doxygen 1.5.7.1