src/vfer_control.h File Reference

Header file for control.c. More...

#include "vfer.h"
#include "vfer_packet.h"
#include "vfer_datagram.h"
#include "vfer_func_rel.h"

Go to the source code of this file.

Functions

int Control_Accept (vfer_sock *skt, vfer_sock *ret_skt)
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)
void Control_Register_Socket (vfer_sock *sock)
size_t Control_Send (vfer_sock *sock, const void *buffer, int len)
void Control_Unregister_Socket (vfer_sock *sock)


Detailed Description

Header file for control.c.

Author:
Ivan Beschastnikh
This file suports control.c by defining the necessary structures that the implementation uses to control most of the protocols operations.

Definition in file vfer_control.h.


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.

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.

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.

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.


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