Panda3D
Loading...
Searching...
No Matches
connection.h
Go to the documentation of this file.
1/**
2 * PANDA 3D SOFTWARE
3 * Copyright (c) Carnegie Mellon University. All rights reserved.
4 *
5 * All use of this software is subject to the terms of the revised BSD
6 * license. You should have received a copy of this license along
7 * with this source code in a file named "LICENSE."
8 *
9 * @file connection.h
10 * @author jns
11 * @date 2000-02-07
12 */
13
14#ifndef CONNECTION_H
15#define CONNECTION_H
16
17#include "pandabase.h"
18#include "referenceCount.h"
19#include "netAddress.h"
20#include "lightReMutex.h"
21
22class Socket_IP;
24class NetDatagram;
25
26/**
27 * Represents a single TCP or UDP socket for input or output.
28 */
29class EXPCL_PANDA_NET Connection : public ReferenceCount {
30PUBLISHED:
31 explicit Connection(ConnectionManager *manager, Socket_IP *socket);
33
34 NetAddress get_address() const;
36
37 Socket_IP *get_socket() const;
38
39 void set_collect_tcp(bool collect_tcp);
40 bool get_collect_tcp() const;
41 void set_collect_tcp_interval(double interval);
42 double get_collect_tcp_interval() const;
43
44 BLOCKING bool consider_flush();
45 BLOCKING bool flush();
46
47 // Socket options. void set_nonblock(bool flag);
48 void set_linger(bool flag, double time);
49 void set_reuse_addr(bool flag);
50 void set_keep_alive(bool flag);
51 void set_recv_buffer_size(int size);
52 void set_send_buffer_size(int size);
53 void set_ip_time_to_live(int ttl);
54 void set_ip_type_of_service(int tos);
55 void set_no_delay(bool flag);
56 void set_max_segment(int size);
57
58private:
59 bool send_datagram(const NetDatagram &datagram, int tcp_header_size);
60 bool send_raw_datagram(const NetDatagram &datagram);
61 bool do_flush();
62 bool check_send_error(bool okflag);
63
64 ConnectionManager *_manager;
65 Socket_IP *_socket;
66 LightReMutex _write_mutex;
67
68 bool _collect_tcp;
69 double _collect_tcp_interval;
70 double _queued_data_start;
71 std::string _queued_data;
72 int _queued_count;
73
74 friend class ConnectionWriter;
75};
76
77#endif
The primary interface to the low-level networking layer in this package.
void set_collect_tcp(bool collect_tcp)
Enables or disables "collect-tcp" mode.
void set_recv_buffer_size(int size)
Sets the size of the receive buffer, in bytes.
void set_collect_tcp_interval(double interval)
Specifies the interval in time, in seconds, for which to hold TCP packets before sending all of the r...
bool consider_flush()
Sends the most recently queued TCP datagram(s) if enough time has elapsed.
bool flush()
Sends the most recently queued TCP datagram(s) now.
void set_keep_alive(bool flag)
Sets whether the connection is periodically tested to see if it is still alive.
NetAddress get_address() const
Returns the address bound to this connection, if it is a TCP connection.
void set_ip_time_to_live(int ttl)
Sets IP time-to-live.
double get_collect_tcp_interval() const
Returns the interval in time, in seconds, for which to hold TCP packets before sending all of the rec...
void set_reuse_addr(bool flag)
Sets whether local address reuse is allowed.
ConnectionManager * get_manager() const
Returns a pointer to the ConnectionManager object that serves this connection.
void set_linger(bool flag, double time)
Sets whether nonblocking I/O should be in effect.
bool get_collect_tcp() const
Returns the current setting of "collect-tcp" mode.
void set_ip_type_of_service(int tos)
Sets IP type-of-service and precedence.
void set_no_delay(bool flag)
If flag is true, this disables the Nagle algorithm, and prevents delaying of send to coalesce packets...
void set_send_buffer_size(int size)
Sets the size of the send buffer, in bytes.
Connection(ConnectionManager *manager, Socket_IP *socket)
Creates a connection.
void set_max_segment(int size)
Sets the maximum segment size.
Socket_IP * get_socket() const
Returns the internal Socket_IP that defines the connection.
A lightweight reentrant mutex.
Represents a network address to which UDP packets may be sent or to which a TCP socket may be bound.
Definition netAddress.h:25
A specific kind of Datagram, especially for sending across or receiving from a network.
Definition netDatagram.h:40
Base functionality for a INET domain Socket This call should be the starting point for all other unix...
Definition socket_ip.h:27
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.