current version
[opsoft_test.git] / gclib2 / include / dconnection.h
blob14d87f782d7f67f42affae6ca03c6f09455dd385
1 /*
2 * (c) Oleg Puchinin 2006,2007
3 * graycardinalster@gmail.com
4 *
5 */
7 #ifndef DEFINE_DCONNECTION_H
8 #define DEFINE_DCONNECTION_H
10 #include <fcntl.h>
12 #ifndef DEFINE_DUDP_H
13 #include <dudp.h>
14 #endif
16 class DConnection;
17 /// Класс "соединение".
18 class DConnection
20 public:
21 DConnection ();
22 DConnection (int sd);
23 ~DConnection ();
25 int init ();
26 int initUdp ();
27 int reuseAddr ();
28 int bind (char *ip, uint16_t port);
29 int connect (char *ip, uint16_t port = 0);
30 int connectUdp (char *ip, uint16_t port);
31 int listen (int N);
32 Connection * accept ();
33 int send (char * buf, int len);
34 int sendTo (char * buf, int len);
35 int recv (char * buf, int len);
36 int recvFrom (char *buf, int len, char * IP, uint16_t * PORT);
37 DUdp * recvUdp (int bufLen = 65535);
38 void updateCTime (time_t d_time = 0);
39 void updateMTime (time_t d_time = 0);
40 int ioNRead ();
41 int select (int secs, int usecs);
42 Connection * clone ();
43 int setBroadcast ();
44 int setSocket (int m_sd, bool dirty = true);
45 int socket ();
46 int setTimeOut (int t);
47 int timeout ();
48 int close ();
50 void setName (char * m_name);
51 void setGroup (char * m_group);
52 void setRevents (int m_set);
53 void setPollFlags (int m_set);
55 int open (char *f_name, int openmode, int filemode = 0644);
56 int read (char *m_buf, int len);
57 int write (char *m_buf, int len);
58 char * getsockname ();
59 char * getpeername ();
60 uint16_t getpeerport ();
61 uint16_t getsockport ();
62 time_t get_ctime ();
63 time_t get_mtime ();
64 bool broadcast ();
66 char * name ();
67 char * group ();
68 int revents ();
69 int pollFlags ();
71 /* v2.3 */
72 Buf * read ();
73 Buf * recv (int opts = 0);
74 int write (Buf *);
75 int send (Buf *, int opts = 0);
76 List * recvStrings ();
77 int shutdown (int how);
78 char * userData ();
79 char * setUserData (char * ptr);
81 /**/
83 private:
84 char * c_user_data;
85 int c_sd;
86 int c_type;
87 char * c_name;
88 char * c_group;
89 time_t c_mtime;
90 time_t c_ctime;
91 char * c_cname; // client address
92 char * c_pname; // server address
93 uint16_t c_cport;
94 uint16_t c_pport;
95 char * c_status; // other data
96 int c_poll_flags;
97 int c_revents;
98 bool c_bcast;
99 bool dirtySocket;
100 int c_timeout;
101 void prepare ();
104 #endif