#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 |
Definition in file vfer_control.c.
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.
sock | a pointer to a socket structure | |
ret_sock | a pointer to a socket structure that is 'connected' as a result of this call |
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.
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
sock | is a socket pointer |
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.
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. |
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
sock | a socket pointer | |
buffer | a pointer to buffer to which to write received data | |
len | buffer size |
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
sock | socket on which to receive 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
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
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.
sock | a socket pointer | |
buffer | a pointer to data to send | |
len | the length of data in this buffer to send |
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
s | socket on which to send the ccack |
-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
sock | socket link pointer to send data on |
Definition at line 1277 of file vfer_control.c.
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
sock | vfer_sock pointer | |
p | control packet to send on the socket |
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
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).
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.
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()
sock | a pointer to a socket structure |
Definition at line 2405 of file vfer_control.c.
pthread_t ControlT_tid [static] |
Definition at line 40 of file vfer_control.c.