Main Page | Data Structures | File List | Data Fields | Globals | Related Pages

netio.c File Reference

provides functions to read and write to sockets specific to the messages that should be sent for the communication protocol. More...

#include "netio.h"
#include "netio_private.h"
#include "berkeleyapi.h"
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include "util.h"
#include "debug.h"

Go to the source code of this file.

Functions

errorcode readMsg (sock_t sd, comm_type_t type, void *buf, int buf_len)
 reads up to buf_len bytes into buf
errorcode checkMsgLen (char *msg, int msg_len)
 checks that an message is as long as the length field says it is
errorcode sendMsg (sock_t sd, long type, void *payload, long payload_len)
 creates a message from the type and payload and sents it


Detailed Description

provides functions to read and write to sockets specific to the messages that should be sent for the communication protocol.

Author:
Daniel Ferullo (ferullo@cmu.edu)

Definition in file netio.c.


Function Documentation

errorcode checkMsgLen char *  msg,
int  msg_len
 

checks that an message is as long as the length field says it is

Parameters:
msg a pointer to the message
msg_len the length of msg (including header)
Returns:
OK if the message is ok, NOT_OK if it is to small, other neg value otherwise

Definition at line 125 of file netio.c.

References CHECK_NOT_NEG, COMM_LENGTH_LEN, COMM_TYPE_LEN, ERROR_NEG_ARG_2, ERROR_NULL_ARG_1, and errorcode.

Referenced by readMsg().

errorcode readMsg sock_t  sd,
comm_type_t  type,
void *  buf,
int  buf_len
 

reads up to buf_len bytes into buf

This function checks that as it read messages the length field of the header is correct

THIS FUNCTION CONTAINS A COMPLICATED WHILE LOOP THAT IS WORTH A SECOND LOOK!

Parameters:
sd the socket to read from
type the message type to read
buf the buffer to store the message in (the payload only)
buf_len the length of the buffer
Returns:
SUCCESS, errorcode on failure

Definition at line 35 of file netio.c.

References CHECK_NOT_NEG, checkMsgLen(), COMM_HEADER_LEN, comm_type_t, DBG_ALL, DEBUG, ERROR_NEG_ARG_1, ERROR_NEG_ARG_4, errorcode, and safe_free().

Referenced by helper_fsm_buddy_alloc(), helper_fsm_buddy_port(), helper_fsm_conn2(), helper_fsm_end_buddy_bday(), helper_fsm_end_peer_bday(), helper_fsm_goodbye(), helper_fsm_hello(), helper_fsm_start_buddy_bday(), helper_fsm_start_direct_conn(), helper_fsm_start_peer_bday(), peer_fsm_bday_synack_flood(), peer_fsm_buddy_alloc(), peer_fsm_buddy_port(), peer_fsm_check_port_pred(), peer_fsm_conn_again(), peer_fsm_end_bday(), and peer_fsm_forge_syn_ack().

errorcode sendMsg sock_t  sd,
long  type,
void *  payload,
long  payload_len
 

creates a message from the type and payload and sents it

Parameters:
sd the socket to send on
type the message type
payload a pointer to the payload (can be NULL if payload == 0)
payload_len the length of the payload in bytes
Returns:
SUCCESS, neg on failure

Definition at line 152 of file netio.c.

References CHECK_NOT_NEG, COMM_HEADER_LEN, COMM_LENGTH_LEN, COMM_TYPE_LEN, DBG_NETWORK, DEBUG, ERROR_NEG_ARG_1, ERROR_NEG_ARG_4, errorcode, and safe_free().

Referenced by helper_fsm_buddy_alloc(), helper_fsm_buddy_port(), helper_fsm_conn2(), helper_fsm_end_buddy_bday(), helper_fsm_end_peer_bday(), helper_fsm_hello(), helper_fsm_start_buddy_bday(), helper_fsm_start_direct_conn(), helper_fsm_start_peer_bday(), peer_fsm_bday_synack_flood(), peer_fsm_buddy_alloc(), peer_fsm_check_port_pred(), peer_fsm_conn_again(), peer_fsm_end_bday(), peer_fsm_forge_syn_ack(), peer_fsm_hello(), peer_fsm_reply_bday(), peer_fsm_start_bday(), and peer_fsm_start_direct_conn().


Generated on Wed Mar 30 23:20:48 2005 for NATBLASTER by  doxygen 1.3.9.1