Panda3D
 All Classes Functions Variables Enumerations
connection.h
00001 // Filename: connection.h
00002 // Created by:  jns (07Feb00)
00003 //
00004 ////////////////////////////////////////////////////////////////////
00005 //
00006 // PANDA 3D SOFTWARE
00007 // Copyright (c) Carnegie Mellon University.  All rights reserved.
00008 //
00009 // All use of this software is subject to the terms of the revised BSD
00010 // license.  You should have received a copy of this license along
00011 // with this source code in a file named "LICENSE."
00012 //
00013 ////////////////////////////////////////////////////////////////////
00014 
00015 #ifndef CONNECTION_H
00016 #define CONNECTION_H
00017 
00018 #include "pandabase.h"
00019 #include "referenceCount.h"
00020 #include "netAddress.h"
00021 #include "lightReMutex.h"
00022 
00023 class Socket_IP;
00024 class ConnectionManager;
00025 class NetDatagram;
00026 
00027 ////////////////////////////////////////////////////////////////////
00028 //       Class : Connection
00029 // Description : Represents a single TCP or UDP socket for input or
00030 //               output.
00031 ////////////////////////////////////////////////////////////////////
00032 class EXPCL_PANDA_NET Connection : public ReferenceCount {
00033 PUBLISHED:
00034   Connection(ConnectionManager *manager, Socket_IP *socket);
00035   ~Connection();
00036 
00037   NetAddress get_address() const;
00038   ConnectionManager *get_manager() const;
00039 
00040   Socket_IP *get_socket() const;
00041 
00042   void set_collect_tcp(bool collect_tcp);
00043   bool get_collect_tcp() const;
00044   void set_collect_tcp_interval(double interval);
00045   double get_collect_tcp_interval() const;
00046 
00047   BLOCKING bool consider_flush();
00048   BLOCKING bool flush();
00049 
00050   // Socket options.
00051   //  void set_nonblock(bool flag);
00052   void set_linger(bool flag, double time);
00053   void set_reuse_addr(bool flag);
00054   void set_keep_alive(bool flag);
00055   void set_recv_buffer_size(int size);
00056   void set_send_buffer_size(int size);
00057   void set_ip_time_to_live(int ttl);
00058   void set_ip_type_of_service(int tos);
00059   void set_no_delay(bool flag);
00060   void set_max_segment(int size);
00061 
00062 private:
00063   bool send_datagram(const NetDatagram &datagram, int tcp_header_size);
00064   bool send_raw_datagram(const NetDatagram &datagram);
00065   bool do_flush();
00066   bool check_send_error(bool okflag);
00067 
00068   ConnectionManager *_manager;
00069   Socket_IP *_socket;
00070   LightReMutex _write_mutex;
00071 
00072   bool _collect_tcp;
00073   double _collect_tcp_interval;
00074   double _queued_data_start;
00075   string _queued_data;
00076   int _queued_count;
00077 
00078   friend class ConnectionWriter;
00079 };
00080 
00081 #endif
 All Classes Functions Variables Enumerations