src/vfer_control.c File Reference

Implements flow controls, fragmentation, sending, receiving, and acking logic. More...

#include "vfer_control.h"
#include "vfer_ccontrol.h"

Go to the source code of this file.

Functions

int Control_Accept (vfer_sock *sock, vfer_sock *ret_sock)
void Control_Add_Socket (vfer_sock *sock, packet *request, packet *response, packet *ack, char client)
int Control_Close (vfer_sock *sock)
int Control_Connect (vfer_sock *sock)
int Control_Recv (vfer_sock *sock, void *buffer, int len)
static int Control_RecvAll (vfer_sock *sock)
void Control_Register_Socket (vfer_sock *sock)
static void Control_Remove_Socket (vfer_sock *sock)
size_t Control_Send (vfer_sock *sock, const void *buffer, int len)
static int Control_Send_Ack (vfer_sock *s)
static int Control_SendAllData (vfer_sock *sock)
static int Control_SendCtl (vfer_sock *sock, packet *p)
void Control_Unregister_Socket (vfer_sock *sock)
static int Control_Write (packet *p, int fd)
static void ControlT (void *ptr)
static int Unconnect_Rebind (vfer_sock *sock)

Variables

static pthread_t ControlT_tid


Detailed Description

Implements flow controls, fragmentation, sending, receiving, and acking logic.

Author:
Ivan Beschastnikh
This file implements the brains of VFER

Definition in file vfer_control.c.


Function Documentation

int Control_Accept ( vfer_sock sock,
vfer_sock ret_sock 
)

Returns the top connection on te accept queue for a socket.

This function changes the state of ret_sock to CONN_ACCEPTING and blocks in a cond_wait until ControlT threads goes through the handshake, changes the state of ret_sock to CONN_CONNECTED (or something else on error) and signals to this thread to wake up.

Parameters:
sock a pointer to a socket structure
ret_sock a pointer to a socket structure that is 'connected' as a result of this call
Returns:
  • 0 on success
  • VFER_BADSOCK bad vfer_sock
  • VFER_WOULDBLOCK socket is non-blocking and there are no waiting connections
  • VFER_IMPL underlying socket error

Definition at line 73 of file vfer_control.c.

void Control_Add_Socket ( vfer_sock sock,
packet request,
packet response,
packet ack,
char  client 
)

Sets up the socket structure with default parameters based on the initial handshake packets (request/response/ack). It sets the state of the socket to CONN_CONNECTED.

Parameters:
sock socket pointer to a vfer_sock
request request packet corresponding to the new connection
response packet corresponding to the new connection
ack ack corresponding to the new connection
client specifies whether this connection was initiated with a request (client == 1) OR replied to and accepted with a response (client != 1)

Definition at line 2181 of file vfer_control.c.

int Control_Close ( vfer_sock sock  ) 

Sets the socket's state to DISCONNECTED and blocks (if blocking socket) until ControlT thread set socket's state to DISCONNECTED or returns if nonblocking socket Socket's mutex must be locked before calling this function Socket's state must be CONN_CONNECTED before calling this function, this function does not unlock the mutex of the socket

Parameters:
sock is a socket pointer
Returns:
0 on success -2 if socket is nonblocking, will disconnect eventually

Definition at line 265 of file vfer_control.c.

int Control_Connect ( vfer_sock sock  ) 

This function changes the state of the socket to CONN_CONNECTING and either return immediately if the socket is non blocking or blocks waiting on a condition variable for the ControlT thread to signal on it indicating that the socket is connected and is in CONN_CONNECTED state. Follows CONNECT_TIMEOUT (defined in globals.h) for timing out.

Parameters:
sock is a pointer to a socket structure on which to connect. The socket must have its addr field set to the address to connect to.
Returns:
  • 0 on connection succes
  • -1 on connection failure- system connect() call failed

Definition at line 184 of file vfer_control.c.

int Control_Recv ( vfer_sock sock,
void *  buffer,
int  len 
)

Receive data on a socket. This is a function that is called by the client via the api call vfer_recv. The socket's mutex should be locked before calling this function. This function unlocks the socket's mutex before returning. Socket's state must be conn_connected/conn_disconnected/conn_disconnecting on entry

Parameters:
sock a socket pointer
buffer a pointer to buffer to which to write received data
len buffer size
Returns:
  • size of the buffer received on succcess
  • VFER_BADSOCK bad vfer_sock
  • VFER_TIMEOUT timed out while waiting to receive
  • VFER_UNCONN sock is not connected
  • VFER_INVAL invalid buf or len
  • VFER_WOULDBLOCK socket is non-blocking and requested operation would block

Definition at line 393 of file vfer_control.c.

static int Control_RecvAll ( vfer_sock sock  )  [static]

Receives all the packets on a given socket NOTE: socket's mutex must be locked before calling this function

Parameters:
sock socket on which to receive packets
Returns:
-1 on error 0 if received no packets 1 if received only data packets 2 if received only control packets 3 if received both data and control packets

Definition at line 584 of file vfer_control.c.

void Control_Register_Socket ( vfer_sock sock  ) 

This is a helper function that makes the socket passed as argument 'active' so that the ConnectT thread will pay attention to it. It also maintains the sockets.max_fd and the sockets.fds vars which are used as args to the select() call in ControlT thread

Parameters:
sock socket pointer to socket we would like listed as active

Definition at line 463 of file vfer_control.c.

static void Control_Remove_Socket ( vfer_sock sock  )  [static]

Removes a socket from the sockets linked list Control, a thread safe function

Parameters:
sock is a pointer to an vfer_sock

Definition at line 2376 of file vfer_control.c.

size_t Control_Send ( vfer_sock sock,
const void *  buffer,
int  len 
)

Sends data on a socket. This function is called by the client via the api vfer_send call. The socket should be locked before the call to this function. This function unlocks the socket before returning.

Parameters:
sock a socket pointer
buffer a pointer to data to send
len the length of data in this buffer to send
Returns:
-1 on error size of the buffer sent on succcess

Definition at line 313 of file vfer_control.c.

static int Control_Send_Ack ( vfer_sock s  )  [inline, static]

Sends a congestion control ack packet on socket by creating it and then enqueueing it into the control packet queue.

CC is byte accounted (for data carrying packets only) so CC always allows for sending CCAcks

Parameters:
s socket on which to send the ccack
Returns:
0 on success

-1 on error

Definition at line 1241 of file vfer_control.c.

static int Control_SendAllData ( vfer_sock sock  )  [static]

Sends all data packets that need to be sent on a socket

Parameters:
sock socket link pointer to send data on
Returns:
0 on success no packets sent 1 on success some packets sent -1 on sending error

Definition at line 1277 of file vfer_control.c.

static int Control_SendCtl ( vfer_sock sock,
packet p 
) [inline, static]

Sends all the control packets that are in the control packet queue maintained by control.c for each socket NOTE: socket's mutex must be locked before calling this function

Parameters:
sock vfer_sock pointer
p control packet to send on the socket
Returns:
  • 0 on success
  • -1 on error

Definition at line 1211 of file vfer_control.c.

void Control_Unregister_Socket ( vfer_sock sock  ) 

This function removes socket sock from the 'active' list of sockets that are observed by the ControlT thread. This thread takes care to maintain sockets.max_fd and sockets.fds vars

Parameters:
sock is a socket pointer that will be removed from the 'active' list of sockets

Definition at line 498 of file vfer_control.c.

static int Control_Write ( packet p,
int  fd 
) [inline, static]

Writes the iov to an fd and then deallocs the iov (different for DATA, DATAACK iovs).

Returns:
0 on success errno on error (from Packet_Write(), see packet.c)

Definition at line 549 of file vfer_control.c.

static void ControlT ( void *  ptr  )  [static]

Main Control thread that selects on incoming fds, receives all packets, manages timers for congestion control and does a bunch of other logic things for the protocol. This thread goes through the socket linked list and performs the necessary operations to send & recv frames to and from the api land and all of this is marshalled based on the state of each of the sockets.

Parameters:
ptr is not used for anything right now

Definition at line 1425 of file vfer_control.c.

static int Unconnect_Rebind ( vfer_sock sock  )  [static]

Unconnects an vfer_socket and rebinds it

Internal use only, this function is used only by Control_Accept()

Parameters:
sock a pointer to a socket structure
Returns:
0 on success -1 on error

Definition at line 2405 of file vfer_control.c.


Variable Documentation

pthread_t ControlT_tid [static]

Definition at line 40 of file vfer_control.c.


Generated on Tue Aug 8 16:07:21 2006 for VFER by  doxygen 1.4.7