# Connection

from pandac.PandaModules import Connection

Class : Connection
Description : Represents a single TCP or UDP socket for input or output.

## Inheritance:

Connection: ReferenceCount
ReferenceCount:

## Methods of Connection:

considerFlush
flush
getAddress
getCollectTcp
getCollectTcpInterval
getManager
getSocket
setCollectTcp
setCollectTcpInterval
setIpTimeToLive
setIpTypeOfService
setKeepAlive
setLinger
setMaxSegment
setNoDelay
setNonblock
setRecvBufferSize
setReuseAddr
setSendBufferSize

## Methods of ReferenceCount:

getClassType
getRefCount
ref
testRefCountIntegrity
unref

considerFlush bool Connection::consider_flush(void); Description: Sends the most recently queued TCP datagram(s) if enough time has elapsed. This only has meaning if set_collect_tcp() has been set to true.

flush bool Connection::flush(void); Description: Sends the most recently queued TCP datagram(s) now. This only has meaning if set_collect_tcp() has been set to true.

getAddress NetAddress Connection::get_address(void) const; Description: Returns the address bound to this connection, if it is a TCP connection.

getCollectTcp bool Connection::get_collect_tcp(void) const; Description: Returns the current setting of "collect-tcp" mode. See set_collect_tcp().

getCollectTcpInterval double Connection::get_collect_tcp_interval(void) const; Description: Returns the interval in time, in seconds, for which to hold TCP packets before sending all of the recently received packets at once. This only has meaning if "collect-tcp" mode is enabled; see set_collect_tcp().

getManager ConnectionManager *Connection::get_manager(void) const; Description: Returns a pointer to the ConnectionManager object that serves this connection.

getSocket PRFileDesc *Connection::get_socket(void) const; Description: Returns the internal NSPR pointer that defines the connection.

setCollectTcp void Connection::set_collect_tcp(bool collect_tcp); Description: Enables or disables "collect-tcp" mode. In this mode, individual TCP packets are not sent immediately, but rather they are collected together and accumulated to be sent periodically as one larger TCP packet. This cuts down on overhead from the TCP/IP protocol, especially if many small packets need to be sent on the same connection, but it introduces additional latency (since packets must be held before they can be sent). See set_collect_tcp_interval() to specify the interval of time for which to hold packets before sending them. If you enable this mode, you may also need to periodically call consider_flush() to flush the queue if no packets have been sent recently.

setCollectTcpInterval void Connection::set_collect_tcp_interval(double interval); Description: Specifies the interval in time, in seconds, for which to hold TCP packets before sending all of the recently received packets at once. This only has meaning if "collect-tcp" mode is enabled; see set_collect_tcp().

setIpTimeToLive void Connection::set_ip_time_to_live(int ttl); Description: Sets IP time-to-live.

setIpTypeOfService void Connection::set_ip_type_of_service(int tos); Description: Sets IP type-of-service and precedence.

setKeepAlive void Connection::set_keep_alive(bool flag); Description: Sets whether the connection is periodically tested to see if it is still alive.

setLinger void Connection::set_linger(bool flag, double time); Socket options. Description: Sets the time to linger on close if data is present. If flag is false, when you close a socket with data available the system attempts to deliver the data to the peer (the default behavior). If flag is false but time is zero, the system discards any undelivered data when you close the socket. If flag is false but time is nonzero, the system waits up to time seconds to deliver the data.

setMaxSegment void Connection::set_max_segment(int size); Description: Sets the maximum segment size.

setNoDelay void Connection::set_no_delay(bool flag); Description: If flag is true, this disables the Nagle algorithm, and prevents delaying of send to coalesce packets.

setNonblock void Connection::set_nonblock(bool flag); Socket options. Description: Sets whether nonblocking I/O should be in effect.

setRecvBufferSize void Connection::set_recv_buffer_size(int size); Description: Sets the size of the receive buffer, in bytes.

setReuseAddr void Connection::set_reuse_addr(bool flag); Description: Sets whether local address reuse is allowed.

setSendBufferSize void Connection::set_send_buffer_size(int size); Description: Sets the size of the send buffer, in bytes.

getClassType static TypeHandle ReferenceCount::get_class_type(void); Undocumented function.

getRefCount int ReferenceCount::get_ref_count(void) const; Description: Returns the current reference count.

ref void ReferenceCount::ref(void) const; Description: Explicitly increments the reference count. User code should avoid using ref() and unref() directly, which can result in missed reference counts. Instead, let a PointerTo object manage the reference counting automatically. This function is const, even though it changes the object, because generally fiddling with an object's reference count isn't considered part of fiddling with the object. An object might be const in other ways, but we still need to accurately count the number of references to it.

testRefCountIntegrity bool ReferenceCount::test_ref_count_integrity(void) const; Description: Does some easy checks to make sure that the reference count isn't completely bogus. Returns true if ok, false otherwise.

unref bool ReferenceCount::unref(void) const; Description: Explicitly decrements the reference count. Note that the object will not be implicitly deleted by unref() simply because the reference count drops to zero. (Having a member function delete itself is problematic; plus, we don't have a virtual destructor anyway.) However, see the helper function unref_delete(). User code should avoid using ref() and unref() directly, which can result in missed reference counts. Instead, let a PointerTo object manage the reference counting automatically. This function is const, even though it changes the object, because generally fiddling with an object's reference count isn't considered part of fiddling with the object. An object might be const in other ways, but we still need to accurately count the number of references to it. The return value is true if the new reference count is nonzero, false if it is zero.