Panda3D
connection.h
1 // Filename: connection.h
2 // Created by: jns (07Feb00)
3 //
4 ////////////////////////////////////////////////////////////////////
5 //
6 // PANDA 3D SOFTWARE
7 // Copyright (c) Carnegie Mellon University. All rights reserved.
8 //
9 // All use of this software is subject to the terms of the revised BSD
10 // license. You should have received a copy of this license along
11 // with this source code in a file named "LICENSE."
12 //
13 ////////////////////////////////////////////////////////////////////
14 
15 #ifndef CONNECTION_H
16 #define CONNECTION_H
17 
18 #include "pandabase.h"
19 #include "referenceCount.h"
20 #include "netAddress.h"
21 #include "lightReMutex.h"
22 
23 class Socket_IP;
24 class ConnectionManager;
25 class NetDatagram;
26 
27 ////////////////////////////////////////////////////////////////////
28 // Class : Connection
29 // Description : Represents a single TCP or UDP socket for input or
30 // output.
31 ////////////////////////////////////////////////////////////////////
32 class EXPCL_PANDA_NET Connection : public ReferenceCount {
33 PUBLISHED:
34  Connection(ConnectionManager *manager, Socket_IP *socket);
35  ~Connection();
36 
37  NetAddress get_address() const;
38  ConnectionManager *get_manager() const;
39 
40  Socket_IP *get_socket() const;
41 
42  void set_collect_tcp(bool collect_tcp);
43  bool get_collect_tcp() const;
44  void set_collect_tcp_interval(double interval);
45  double get_collect_tcp_interval() const;
46 
47  BLOCKING bool consider_flush();
48  BLOCKING bool flush();
49 
50  // Socket options.
51  // void set_nonblock(bool flag);
52  void set_linger(bool flag, double time);
53  void set_reuse_addr(bool flag);
54  void set_keep_alive(bool flag);
55  void set_recv_buffer_size(int size);
56  void set_send_buffer_size(int size);
57  void set_ip_time_to_live(int ttl);
58  void set_ip_type_of_service(int tos);
59  void set_no_delay(bool flag);
60  void set_max_segment(int size);
61 
62 private:
63  bool send_datagram(const NetDatagram &datagram, int tcp_header_size);
64  bool send_raw_datagram(const NetDatagram &datagram);
65  bool do_flush();
66  bool check_send_error(bool okflag);
67 
68  ConnectionManager *_manager;
69  Socket_IP *_socket;
70  LightReMutex _write_mutex;
71 
72  bool _collect_tcp;
73  double _collect_tcp_interval;
74  double _queued_data_start;
75  string _queued_data;
76  int _queued_count;
77 
78  friend class ConnectionWriter;
79 };
80 
81 #endif
A specific kind of Datagram, especially for sending across or receiving from a network.
Definition: netDatagram.h:43
Base functionality for a INET domain Socket this call should be the starting point for all other unix...
Definition: socket_ip.h:34
The primary interface to the low-level networking layer in this package.
A lightweight reentrant mutex.
Definition: lightReMutex.h:34
This class handles threaded delivery of datagrams to various TCP or UDP sockets.
A base class for all things that want to be reference-counted.
Represents a single TCP or UDP socket for input or output.
Definition: connection.h:32
Represents a network address to which UDP packets may be sent or to which a TCP socket may be bound...
Definition: netAddress.h:27