00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef CONNECTION_H
00020 #define CONNECTION_H
00021
00022 #include "pandabase.h"
00023 #include "referenceCount.h"
00024 #include "netAddress.h"
00025
00026 #include <prio.h>
00027 #include <prlock.h>
00028 #include <prerror.h>
00029
00030 class ConnectionManager;
00031 class NetDatagram;
00032
00033
00034
00035
00036
00037
00038 class EXPCL_PANDA Connection : public ReferenceCount {
00039 PUBLISHED:
00040 Connection(ConnectionManager *manager, PRFileDesc *socket);
00041 ~Connection();
00042
00043 NetAddress get_address() const;
00044 ConnectionManager *get_manager() const;
00045
00046 PRFileDesc *get_socket() const;
00047
00048 void set_collect_tcp(bool collect_tcp);
00049 bool get_collect_tcp() const;
00050 void set_collect_tcp_interval(double interval);
00051 double get_collect_tcp_interval() const;
00052
00053 bool consider_flush();
00054 bool flush();
00055
00056
00057 void set_nonblock(bool flag);
00058 void set_linger(bool flag, double time);
00059 void set_reuse_addr(bool flag);
00060 void set_keep_alive(bool flag);
00061 void set_recv_buffer_size(int size);
00062 void set_send_buffer_size(int size);
00063 void set_ip_time_to_live(int ttl);
00064 void set_ip_type_of_service(int tos);
00065 void set_no_delay(bool flag);
00066 void set_max_segment(int size);
00067
00068 private:
00069 bool send_datagram(const NetDatagram &datagram);
00070 bool send_raw_datagram(const NetDatagram &datagram);
00071 bool do_flush();
00072 bool check_send_error(PRInt32 result, PRErrorCode errcode, PRInt32 bytes_to_send);
00073
00074 ConnectionManager *_manager;
00075 PRFileDesc *_socket;
00076 PRLock *_write_mutex;
00077
00078 bool _collect_tcp;
00079 double _collect_tcp_interval;
00080 double _queued_data_start;
00081 string _queued_data;
00082 int _queued_count;
00083
00084 friend class ConnectionWriter;
00085 };
00086
00087 #endif