File modules/sk/cd_socket.c

  $Revision: 1.2 $

Socket module - cd_socket.c - basic read/write socket routines defined in terms of connection data structures with timeouts and storing information about broken connections.
Status: NOT REVUED, TESTED
Design and implementation by Marek Bukowy.

Included Files


Preprocessor definitions

#define SKBUFLEN 2047

Global Function SK_cd_close()

  Wrapper around the close(2) system call, 

  Author:
        marek
int SK_cd_close ( sk_conn_st* condat )
int SK_cd_close
returns the error codes of close(2).
sk_conn_st* condat
Pointer to the connection data structure.
Prototyped in: modules/sk/sk.h
Calls: SK_close()
Called by: PM_interact()modules/pm/protocol_mirror.c

Global Function SK_cd_free()

  Destroys the data allocated and anchored by the connection data structure.
void SK_cd_free ( sk_conn_st* condat )
sk_conn_st* condat
Pointer to the connection data structure.
Prototyped in: modules/sk/sk.h
Calls: wr_real_free()
Called by: PW_interact()modules/pw/protocol_whois.c

Global Function SK_cd_gets()

  Read from a socket, until a linefeed character is received or the buffer
  fills up to the maximum size "count". If the connection data has non-zero
  timeout value for reading, it is used here between calls to read 
  the next 1 character.

More: if the connection structure has bad status for this connection from previous calls, no read will be attempted.
  Author:
        marek

Side Effects: broken connections get registered in the connection structure.
int SK_cd_gets ( sk_conn_st* condat, char* str, size_t count )
int SK_cd_gets
Returns the total_count of bytes read, or inverted error codes (negative numbers): (- SK_DISCONNECT) on broken connection, (- SK_TIMEOUT) on timeout.
sk_conn_st* condat
connection data
char* str
The buffer to store the data received from the socket.
size_t count
size of the buffer.
Prototyped in: modules/sk/sk.h
Calls: fprintf(), memset(), read(), select()
Called by: PC_interact()modules/pc/protocol_config.c
  PM_interact()modules/pm/protocol_mirror.c
  PW_interact()modules/pw/protocol_whois.c
  authenticate_user()modules/pc/protocol_config.c

Global Function SK_cd_make()

  Construct a connection data given the socket or file descriptor.
  Also performs the getpeername check and stores the IP in an allocated
  string.
void SK_cd_make ( sk_conn_st* condat, int sock, unsigned timeout )
sk_conn_st* condat
pointer to where the data is to be stored.
int sock
The socket or file descriptor.
unsigned timeout
Read timeout (used in SK_cd_gets) in seconds. Value of 0 disables the timeout.
Prototyped in: modules/sk/sk.h
Calls: SK_getpeerip(), SK_getpeername(), fprintf(), memset()
Called by: PW_interact()modules/pw/protocol_whois.c

Global Function SK_cd_printf()

  Printf-like function to print to socket/file specified by connection
  data structure. First writes the text to a temporary buffer, then
  uses SK_cd_puts to print it. Maintains a 2K static buffer, and allocates
  more memory if this is not enough.


  Author:
        marek
int SK_cd_printf ( sk_conn_st* condat, char* txt, ... )
int SK_cd_printf
Returns the SK_cd_puts error code/return value.
sk_conn_st* condat
Pointer to the connection data structure.
char* txt
Format text to be written
...
more arguments (like printf)
Prototyped in: modules/sk/sk.h
Calls: NOERR()modules/er/er.c
  SK_cd_puts()modules/sk/cd_socket.c
  __builtin_next_arg(), __builtin_saveregs(), fprintf(), vsnprintf(), wr_real_free(), wr_real_malloc()
Called by: PC_interact()modules/pc/protocol_config.c
  QC_fill()modules/qc/query_command.c
  er_macro_list_hook()modules/er/er_macro.c
  process_input()modules/pc/protocol_config.c
  qi_prep_run_refer()modules/qi/query_instructions.c
  show_uptime()modules/pc/pc_commands.c

Global Function SK_cd_puts()

   This function writes a character string out to a socket, unless 
   the connection is broken. 

char *str The buffer to be written to the socket.
More: if the connection structure has bad status for this connection from previous calls, no write will be attempted.
  Author:
        marek

Side Effects: broken connections get registered in the connection structure
int SK_cd_puts ( sk_conn_st* condat, const char* str )
int SK_cd_puts
Returns the total_count of bytes written, or inverted error codes (negative numbers): (- SK_DISCONNECT) on broken connection, (- SK_INTERRUPT) on control-c received, (- SK_TIMEOUT) on timeout.
sk_conn_st* condat
Pointer to the connection data structure.
const char* str
&nbs;
Prototyped in: modules/sk/sk.h
Calls: SK_puts(), fprintf()
Called by: PC_interact()modules/pc/protocol_config.c
  PM_interact()modules/pm/protocol_mirror.c
  PW_interact()modules/pw/protocol_whois.c
  PW_process_qc()modules/pw/protocol_whois.c
  QC_fill()modules/qc/query_command.c
  SK_cd_printf()modules/sk/cd_socket.c
  __report_sql_error()modules/qi/query_instructions.c
  authenticate_user()modules/pc/protocol_config.c
  display_file()modules/pw/protocol_whois.c
  process_input()modules/pc/protocol_config.c
  qi_prep_run_refer()modules/qi/query_instructions.c
  run_referral()modules/qi/query_instructions.c
  rx_space_printone()modules/rx/rx_print.c
  rx_tree_print()modules/rx/rx_print.c
  rx_walk_hook_printnode()modules/rx/rx_print.c
  write_radix_immediate()modules/qi/query_instructions.c
  write_results()modules/qi/query_instructions.c