vrpn 07.35
Virtual Reality Peripheral Network
Loading...
Searching...
No Matches
vrpn_Endpoint_IP Class Reference

Encapsulation of the data and methods for a single IP-based connection to take care of one part of many clients talking to a single server. More...

#include <vrpn_Connection.h>

Inheritance diagram for vrpn_Endpoint_IP:
Collaboration diagram for vrpn_Endpoint_IP:

Public Member Functions

 vrpn_Endpoint_IP (vrpn_TypeDispatcher *dispatcher, vrpn_int32 *connectedEndpointCounter)
 
virtual ~vrpn_Endpoint_IP (void)
 
Accessors
virtual vrpn_bool doing_okay (void) const
 
vrpn_bool outbound_udp_open (void) const
 True if the UDP outbound is open, False if not.
 
vrpn_int32 tcp_outbuf_size (void) const
 
vrpn_int32 udp_outbuf_size (void) const
 
- Public Member Functions inherited from vrpn_Endpoint
 vrpn_Endpoint (vrpn_TypeDispatcher *dispatcher, vrpn_int32 *connectedEndpointCounter)
 
virtual ~vrpn_Endpoint (void)
 
int pack_log_description (void)
 Packs the log description set by setup_new_connection().
 
int pack_sender_description (vrpn_int32 which)
 Packs a sender description over our socket.
 
int pack_type_description (vrpn_int32 which)
 Packs a type description.
 
int local_type_id (vrpn_int32 remote_type) const
 Returns the local mapping for the remote type (-1 if none).
 
int local_sender_id (vrpn_int32 remote_sender) const
 Returns the local mapping for the remote sender (-1 if none).
 
void init (void)
 
void clear_other_senders_and_types (void)
 Clear out the remote mapping list. This is done when a connection is dropped and we want to try and re-establish it.
 
int newLocalSender (const char *name, vrpn_int32 which)
 A new local sender or type has been established; set the local type for it if the other side has declared it. Return 1 if the other side has one, 0 if not.
 
int newLocalType (const char *name, vrpn_int32 which)
 
int newRemoteType (cName type_name, vrpn_int32 remote_id, vrpn_int32 local_id)
 Adds a new remote type/sender and returns its index. Returns -1 on error.
 
int newRemoteSender (cName sender_name, vrpn_int32 remote_id, vrpn_int32 local_id)
 
void setConnection (vrpn_Connection *conn)
 
vrpn_ConnectiongetConnection ()
 
void setLogNames (const char *inName, const char *outName)
 
int openLogs (void)
 

Manipulators

SOCKET d_tcpSocket
 
SOCKET d_tcpListenSocket
 This section deals with when a client connection is trying to establish (or re-establish) a connection with its server. It keeps track of what we need to know to make this happen.
 
int d_tcpListenPort
 Socket and port that the client listens on when lobbing datagrams at the server and waiting for it to call back.
 
SOCKET d_udpLobSocket
 Socket to use to lob UDP requests asking for the server to call us back.
 
char * d_remote_machine_name
 Machine to call.
 
int d_remote_port_number
 Port to connect to on remote machine.
 
timeval d_last_connect_attempt
 When the last UDP lob occurred.
 
vrpn_bool d_tcp_only
 For connections made through firewalls or NAT with the tcp: URL, we do not want to allow the endpoints on either end to open a UDP link to their counterparts. If this is the case, then this flag should be set to true.
 
SOCKET d_udpOutboundSocket
 
SOCKET d_udpInboundSocket
 Inbound unreliable messages come here. Need one for each due to different clock synchronization for each; we need to know which server each message is from.
 
char * d_tcpOutbuf
 
char * d_udpOutbuf
 
vrpn_int32 d_tcpBuflen
 
vrpn_int32 d_udpBuflen
 
vrpn_int32 d_tcpNumOut
 
vrpn_int32 d_udpNumOut
 
vrpn_int32 d_tcpSequenceNumber
 
vrpn_int32 d_udpSequenceNumber
 
vrpn_float64 d_tcpAlignedInbuf [vrpn_CONNECTION_TCP_BUFLEN/sizeof(vrpn_float64)+1]
 
vrpn_float64 d_udpAlignedInbuf [vrpn_CONNECTION_UDP_BUFLEN/sizeof(vrpn_float64)+1]
 
char * d_tcpInbuf
 
char * d_udpInbuf
 
char * d_NICaddress
 
void init (void)
 
int mainloop (timeval *timeout)
 
int pack_message (vrpn_uint32 len, struct timeval time, vrpn_int32 type, vrpn_int32 sender, const char *buffer, vrpn_uint32 class_of_service)
 Pack a message that will be sent the next time mainloop() is called.
 
virtual int send_pending_reports (void)
 send pending report, clear the buffer.
 
int pack_udp_description (int portno)
 
int handle_tcp_messages (const timeval *timeout)
 
int handle_udp_messages (const timeval *timeout)
 
int connect_tcp_to (const char *msg)
 
int connect_tcp_to (const char *addr, int port)
 Connects d_tcpSocket to the specified address (msg = "IP port"); sets status to COOKIE_PENDING; returns 0 on success, -1 on failure.
 
int connect_udp_to (const char *addr, int port)
 Connects d_udpSocket to the specified address and port; returns 0 on success, sets status to BROKEN and returns -1 on failure.
 
int setup_new_connection (void)
 Sends the magic cookie and other information to its peer. It is called by both the client and server setup routines.
 
void poll_for_cookie (const timeval *timeout=NULL)
 
int finish_new_connection_setup (void)
 
void drop_connection (void)
 Should only be called by vrpn_Connection::drop_connection(), since there's more housecleaning to do at that level. I suppose that argues against separating this function out.
 
void clearBuffers (void)
 Empties out the TCP and UDP send buffers. Needed by vrpn_FileConnection to get at {udp,tcp}NumOut.
 
void setNICaddress (const char *)
 
int getOneTCPMessage (int fd, char *buf, size_t buflen)
 
int getOneUDPMessage (char *buf, size_t buflen)
 

Additional Inherited Members

- Static Public Member Functions inherited from vrpn_Endpoint
static int VRPN_CALLBACK handle_sender_message (void *userdata, vrpn_HANDLERPARAM p)
 
static int VRPN_CALLBACK handle_type_message (void *userdata, vrpn_HANDLERPARAM p)
 
- Public Attributes inherited from vrpn_Endpoint
int status
 
long d_remoteLogMode
 Mode to put the remote logging in.
 
char * d_remoteInLogName
 Name of the remote log file.
 
char * d_remoteOutLogName
 Name of the remote log file.
 
char rhostname [150]
 
vrpn_Logd_inLog
 
vrpn_Logd_outLog
 
- Protected Member Functions inherited from vrpn_Endpoint
virtual int dispatch (vrpn_int32 type, vrpn_int32 sender, timeval time, vrpn_uint32 payload_len, char *bufptr)
 
int tryToMarshall (char *outbuf, vrpn_int32 &buflen, vrpn_int32 &numOut, vrpn_uint32 len, timeval time, vrpn_int32 type, vrpn_int32 sender, const char *buffer, vrpn_uint32 classOfService)
 Calls marshall_message(); if that fails, calls send_pending_reports() and then marshalls again. Returns the number of characters successfully marshalled.
 
int marshall_message (char *outbuf, vrpn_uint32 outbuf_size, vrpn_uint32 initial_out, vrpn_uint32 len, struct timeval time, vrpn_int32 type, vrpn_int32 sender, const char *buffer, vrpn_uint32 sequenceNumber)
 Marshal the message into the buffer if it will fit.
 
- Protected Attributes inherited from vrpn_Endpoint
vrpn_TranslationTabled_senders
 
vrpn_TranslationTabled_types
 
vrpn_TypeDispatcherd_dispatcher
 
vrpn_int32 * d_connectionCounter
 
vrpn_Connectiond_parent
 

Detailed Description

Encapsulation of the data and methods for a single IP-based connection to take care of one part of many clients talking to a single server.

This will only be used from within the vrpn_Connection_IP class; it should not be instantiated by users or devices. Should not be visible!

Definition at line 422 of file vrpn_Connection.h.

Constructor & Destructor Documentation

◆ vrpn_Endpoint_IP()

vrpn_Endpoint_IP::vrpn_Endpoint_IP ( vrpn_TypeDispatcher * dispatcher,
vrpn_int32 * connectedEndpointCounter )

Definition at line 2778 of file vrpn_Connection.C.

References d_tcpBuflen, d_tcpOutbuf, d_udpBuflen, d_udpOutbuf, and init().

Here is the call graph for this function:

◆ ~vrpn_Endpoint_IP()

Member Function Documentation

◆ clearBuffers()

void vrpn_Endpoint_IP::clearBuffers ( void )
virtual

Empties out the TCP and UDP send buffers. Needed by vrpn_FileConnection to get at {udp,tcp}NumOut.

Implements vrpn_Endpoint.

Definition at line 3902 of file vrpn_Connection.C.

References d_tcpNumOut, and d_udpNumOut.

Referenced by drop_connection(), send_pending_reports(), and vrpn_File_Connection::send_pending_reports().

◆ connect_tcp_to() [1/2]

int vrpn_Endpoint_IP::connect_tcp_to ( const char * addr,
int port )

Connects d_tcpSocket to the specified address (msg = "IP port"); sets status to COOKIE_PENDING; returns 0 on success, -1 on failure.

Definition at line 3703 of file vrpn_Connection.C.

References BROKEN, COOKIE_PENDING, d_NICaddress, d_tcp_only, d_tcpSocket, SOCK_CAST, vrpn_Endpoint::status, and vrpn_closeSocket.

◆ connect_tcp_to() [2/2]

int vrpn_Endpoint_IP::connect_tcp_to ( const char * msg)

Definition at line 3690 of file vrpn_Connection.C.

References connect_tcp_to().

Referenced by connect_tcp_to(), vrpn_Connection_IP::connect_to_client(), mainloop(), and vrpn_Connection_IP::server_check_for_incoming_connections().

Here is the call graph for this function:

◆ connect_udp_to()

int vrpn_Endpoint_IP::connect_udp_to ( const char * addr,
int port )

Connects d_udpSocket to the specified address and port; returns 0 on success, sets status to BROKEN and returns -1 on failure.

Definition at line 3817 of file vrpn_Connection.C.

References BROKEN, d_NICaddress, d_tcp_only, d_udpOutboundSocket, and vrpn_Endpoint::status.

Referenced by vrpn_Connection_IP::handle_UDP_message().

◆ doing_okay()

vrpn_bool vrpn_Endpoint_IP::doing_okay ( void ) const
virtual

Implements vrpn_Endpoint.

Definition at line 2946 of file vrpn_Connection.C.

References LOGGING, vrpn_Endpoint::status, and TRYING_TO_CONNECT.

Referenced by poll_for_cookie().

◆ drop_connection()

void vrpn_Endpoint_IP::drop_connection ( void )
virtual

Should only be called by vrpn_Connection::drop_connection(), since there's more housecleaning to do at that level. I suppose that argues against separating this function out.

Implements vrpn_Endpoint.

Definition at line 3831 of file vrpn_Connection.C.

References vrpn_Endpoint::clear_other_senders_and_types(), clearBuffers(), vrpn_Log::close(), vrpn_Endpoint::d_connectionCounter, vrpn_Endpoint::d_dispatcher, vrpn_Endpoint::d_outLog, d_tcpNumOut, d_tcpSocket, d_udpInboundSocket, d_udpNumOut, d_udpOutboundSocket, INVALID_SOCKET, vrpn_Log::logMessage(), vrpn_Log::logMode(), vrpn_closeSocket, vrpn_CONNECTION_DISCONNECT_MESSAGE, vrpn_CONTROL, vrpn_dropped_connection, vrpn_dropped_last_connection, and vrpn_gettimeofday.

Referenced by vrpn_File_Connection::reset().

Here is the call graph for this function:

◆ finish_new_connection_setup()

◆ getOneTCPMessage()

int vrpn_Endpoint_IP::getOneTCPMessage ( int fd,
char * buf,
size_t buflen )
protected

Definition at line 4164 of file vrpn_Connection.C.

References vrpn_Endpoint::d_inLog, vrpn_Endpoint::dispatch(), vrpn_Log::logIncomingMessage(), vrpn_ALIGN, and vrpn_noint_block_read().

Referenced by handle_tcp_messages().

Here is the call graph for this function:

◆ getOneUDPMessage()

int vrpn_Endpoint_IP::getOneUDPMessage ( char * buf,
size_t buflen )
protected

Definition at line 4249 of file vrpn_Connection.C.

References vrpn_Endpoint::d_inLog, vrpn_Endpoint::dispatch(), vrpn_Endpoint::local_type_id(), vrpn_Log::logIncomingMessage(), and vrpn_ALIGN.

Referenced by handle_udp_messages().

Here is the call graph for this function:

◆ handle_tcp_messages()

int vrpn_Endpoint_IP::handle_tcp_messages ( const timeval * timeout)

Definition at line 3511 of file vrpn_Connection.C.

References vrpn_Endpoint::d_parent, d_tcpAlignedInbuf, d_tcpInbuf, d_tcpSocket, vrpn_Connection::get_Jane_value(), getOneTCPMessage(), and vrpn_noint_select().

Referenced by mainloop().

Here is the call graph for this function:

◆ handle_udp_messages()

int vrpn_Endpoint_IP::handle_udp_messages ( const timeval * timeout)

Definition at line 3596 of file vrpn_Connection.C.

References vrpn_Endpoint::d_parent, d_udpAlignedInbuf, d_udpInboundSocket, d_udpInbuf, vrpn_Connection::get_Jane_value(), getOneUDPMessage(), and vrpn_noint_select().

Referenced by mainloop().

Here is the call graph for this function:

◆ init()

void vrpn_Endpoint_IP::init ( void )

◆ mainloop()

◆ outbound_udp_open()

vrpn_bool vrpn_Endpoint_IP::outbound_udp_open ( void ) const

True if the UDP outbound is open, False if not.

Definition at line 2927 of file vrpn_Connection.C.

References d_udpOutboundSocket.

◆ pack_message()

int vrpn_Endpoint_IP::pack_message ( vrpn_uint32 len,
struct timeval time,
vrpn_int32 type,
vrpn_int32 sender,
const char * buffer,
vrpn_uint32 class_of_service )
virtual

Pack a message that will be sent the next time mainloop() is called.

Pack a message into the appropriate output buffer (TCP or UDP) depending on the class of service for the message, and handle logging for the message (but not filtering).

Turn off the RELIABLE flag if you want low-latency (UDP) send.

This function does not handle semantic checking, local callbacks and filtering. (these must be done in the vrpn_Connection class routine that calls this one).

Parameters: The length of the message, the local-clock time value for the message, the type and sender IDs for the message, the buffer that holds the message contents, and the class of service (currently, only reliable/unreliable is used).

Returns 0 on success and -1 on failure.

Implements vrpn_Endpoint.

Definition at line 3248 of file vrpn_Connection.C.

References CONNECTED, vrpn_Endpoint::d_outLog, d_tcpBuflen, d_tcpNumOut, d_tcpOutbuf, d_tcpSequenceNumber, d_tcpSocket, d_udpBuflen, d_udpNumOut, d_udpOutboundSocket, d_udpOutbuf, d_udpSequenceNumber, LOGGING, vrpn_Log::logOutgoingMessage(), vrpn_Endpoint::status, vrpn_Endpoint::tryToMarshall(), and vrpn_CONNECTION_RELIABLE.

Referenced by pack_udp_description().

Here is the call graph for this function:

◆ pack_udp_description()

int vrpn_Endpoint_IP::pack_udp_description ( int portno)

Definition at line 3414 of file vrpn_Connection.C.

References d_NICaddress, d_tcpSocket, pack_message(), vrpn_CONNECTION_RELIABLE, vrpn_CONNECTION_UDP_DESCRIPTION, and vrpn_gettimeofday.

Referenced by finish_new_connection_setup().

Here is the call graph for this function:

◆ poll_for_cookie()

void vrpn_Endpoint_IP::poll_for_cookie ( const timeval * timeout = NULL)
virtual

Implements vrpn_Endpoint.

Definition at line 3966 of file vrpn_Connection.C.

References BROKEN, CONNECTED, d_remote_machine_name, d_tcpSocket, doing_okay(), finish_new_connection_setup(), vrpn_Endpoint::status, and vrpn_noint_select().

Referenced by mainloop(), and setup_new_connection().

Here is the call graph for this function:

◆ send_pending_reports()

int vrpn_Endpoint_IP::send_pending_reports ( void )
virtual

send pending report, clear the buffer.

This function was protected, now is public, so we can use it to send out intermediate results without calling mainloop

Implements vrpn_Endpoint.

Definition at line 3316 of file vrpn_Connection.C.

References BROKEN, clearBuffers(), d_tcpNumOut, d_tcpOutbuf, d_tcpSocket, d_udpNumOut, d_udpOutboundSocket, d_udpOutbuf, vrpn_Endpoint::status, TRYING_TO_CONNECT, vrpn_noint_select(), vrpn_socket_error, and vrpn_socket_error_to_chars.

Referenced by finish_new_connection_setup(), and mainloop().

Here is the call graph for this function:

◆ setNICaddress()

void vrpn_Endpoint_IP::setNICaddress ( const char * address)

◆ setup_new_connection()

int vrpn_Endpoint_IP::setup_new_connection ( void )
virtual

Sends the magic cookie and other information to its peer. It is called by both the client and server setup routines.

Implements vrpn_Endpoint.

Definition at line 3936 of file vrpn_Connection.C.

References BROKEN, COOKIE_PENDING, vrpn_Endpoint::d_remoteLogMode, d_tcpSocket, poll_for_cookie(), vrpn_Endpoint::status, vrpn_cookie_size(), vrpn_noint_block_write(), and write_vrpn_cookie().

Referenced by mainloop().

Here is the call graph for this function:

◆ tcp_outbuf_size()

vrpn_int32 vrpn_Endpoint_IP::tcp_outbuf_size ( void ) const

Definition at line 2942 of file vrpn_Connection.C.

References d_tcpBuflen.

◆ udp_outbuf_size()

vrpn_int32 vrpn_Endpoint_IP::udp_outbuf_size ( void ) const

Definition at line 2944 of file vrpn_Connection.C.

References d_udpBuflen.

Member Data Documentation

◆ d_last_connect_attempt

timeval vrpn_Endpoint_IP::d_last_connect_attempt

When the last UDP lob occurred.

Definition at line 515 of file vrpn_Connection.h.

Referenced by init(), and mainloop().

◆ d_NICaddress

char* vrpn_Endpoint_IP::d_NICaddress
protected

◆ d_remote_machine_name

char* vrpn_Endpoint_IP::d_remote_machine_name

◆ d_remote_port_number

int vrpn_Endpoint_IP::d_remote_port_number

Port to connect to on remote machine.

Definition at line 514 of file vrpn_Connection.h.

Referenced by mainloop(), and vrpn_Connection_IP::server_check_for_incoming_connections().

◆ d_tcp_only

vrpn_bool vrpn_Endpoint_IP::d_tcp_only

For connections made through firewalls or NAT with the tcp: URL, we do not want to allow the endpoints on either end to open a UDP link to their counterparts. If this is the case, then this flag should be set to true.

Definition at line 517 of file vrpn_Connection.h.

Referenced by connect_tcp_to(), connect_udp_to(), finish_new_connection_setup(), mainloop(), and vrpn_Connection_IP::server_check_for_incoming_connections().

◆ d_tcpAlignedInbuf

vrpn_float64 vrpn_Endpoint_IP::d_tcpAlignedInbuf[vrpn_CONNECTION_TCP_BUFLEN/sizeof(vrpn_float64)+ 1]
protected

Definition at line 546 of file vrpn_Connection.h.

Referenced by handle_tcp_messages().

◆ d_tcpBuflen

vrpn_int32 vrpn_Endpoint_IP::d_tcpBuflen
protected

Definition at line 537 of file vrpn_Connection.h.

Referenced by pack_message(), tcp_outbuf_size(), and vrpn_Endpoint_IP().

◆ d_tcpInbuf

char* vrpn_Endpoint_IP::d_tcpInbuf
protected

Definition at line 551 of file vrpn_Connection.h.

Referenced by handle_tcp_messages().

◆ d_tcpListenPort

int vrpn_Endpoint_IP::d_tcpListenPort

Socket and port that the client listens on when lobbing datagrams at the server and waiting for it to call back.

Definition at line 504 of file vrpn_Connection.h.

Referenced by init(), and mainloop().

◆ d_tcpListenSocket

SOCKET vrpn_Endpoint_IP::d_tcpListenSocket

This section deals with when a client connection is trying to establish (or re-establish) a connection with its server. It keeps track of what we need to know to make this happen.

Definition at line 503 of file vrpn_Connection.h.

Referenced by init(), mainloop(), and ~vrpn_Endpoint_IP().

◆ d_tcpNumOut

vrpn_int32 vrpn_Endpoint_IP::d_tcpNumOut
protected

◆ d_tcpOutbuf

char* vrpn_Endpoint_IP::d_tcpOutbuf
protected

◆ d_tcpSequenceNumber

vrpn_int32 vrpn_Endpoint_IP::d_tcpSequenceNumber
protected

Definition at line 542 of file vrpn_Connection.h.

Referenced by pack_message().

◆ d_tcpSocket

SOCKET vrpn_Endpoint_IP::d_tcpSocket
Todo
XXX These should be protected; making them so will lead to making the code split the functions between Endpoint and Connection protected:

Definition at line 497 of file vrpn_Connection.h.

Referenced by connect_tcp_to(), drop_connection(), finish_new_connection_setup(), handle_tcp_messages(), init(), mainloop(), pack_message(), pack_udp_description(), poll_for_cookie(), send_pending_reports(), vrpn_Connection_IP::server_check_for_incoming_connections(), setup_new_connection(), and ~vrpn_Endpoint_IP().

◆ d_udpAlignedInbuf

vrpn_float64 vrpn_Endpoint_IP::d_udpAlignedInbuf[vrpn_CONNECTION_UDP_BUFLEN/sizeof(vrpn_float64)+ 1]
protected

Definition at line 549 of file vrpn_Connection.h.

Referenced by handle_udp_messages().

◆ d_udpBuflen

vrpn_int32 vrpn_Endpoint_IP::d_udpBuflen
protected

Definition at line 538 of file vrpn_Connection.h.

Referenced by pack_message(), udp_outbuf_size(), and vrpn_Endpoint_IP().

◆ d_udpInboundSocket

SOCKET vrpn_Endpoint_IP::d_udpInboundSocket
protected

Inbound unreliable messages come here. Need one for each due to different clock synchronization for each; we need to know which server each message is from.

Todo
XXX Now that we don't need multiple clocks, can we collapse this?

Definition at line 528 of file vrpn_Connection.h.

Referenced by drop_connection(), finish_new_connection_setup(), handle_udp_messages(), init(), mainloop(), and ~vrpn_Endpoint_IP().

◆ d_udpInbuf

char* vrpn_Endpoint_IP::d_udpInbuf
protected

Definition at line 552 of file vrpn_Connection.h.

Referenced by handle_udp_messages().

◆ d_udpLobSocket

SOCKET vrpn_Endpoint_IP::d_udpLobSocket

Socket to use to lob UDP requests asking for the server to call us back.

Definition at line 511 of file vrpn_Connection.h.

Referenced by init(), mainloop(), and ~vrpn_Endpoint_IP().

◆ d_udpNumOut

vrpn_int32 vrpn_Endpoint_IP::d_udpNumOut
protected

◆ d_udpOutboundSocket

SOCKET vrpn_Endpoint_IP::d_udpOutboundSocket
protected

◆ d_udpOutbuf

char* vrpn_Endpoint_IP::d_udpOutbuf
protected

◆ d_udpSequenceNumber

vrpn_int32 vrpn_Endpoint_IP::d_udpSequenceNumber
protected

Definition at line 543 of file vrpn_Connection.h.

Referenced by pack_message().


The documentation for this class was generated from the following files: