source: abuse/trunk/src/net/include/sock.hpp @ 2

Last change on this file since 2 was 2, checked in by Sam Hocevar, 18 years ago
  • imported original 0.7.0 tarball
File size: 3.6 KB
Line 
1#ifndef __SOCK_HPP_
2#define __SOCK_HPP_
3
4extern const char notify_signature[];
5extern const char notify_response[];
6
7class net_address
8{
9  public :
10  enum protocol { IP, IPX, MODEM, NETBIOS, OTHER };
11  virtual protocol protocol_type() const = 0;
12  virtual int equal(const net_address *who) const = 0;
13  int operator==(const net_address &who) { return equal(&who); }
14  virtual int set_port(int port) = 0;
15  virtual int get_port() = 0;
16  virtual void print()               { ; }
17  virtual net_address *copy()    = 0;
18  virtual void store_string(char *st, int st_length) = 0;    // this should be able to be used get_node_address()
19} ;
20
21
22class net_socket
23{
24  public :
25  enum socket_type { SOCKET_SECURE, SOCKET_FAST } ;
26
27  virtual int error()                                              = 0;
28  virtual int ready_to_read()                                      = 0;
29  virtual int ready_to_write()                                     = 0;
30  virtual int write(void *buf, int size, net_address *addr=0)   = 0;
31  virtual int read(void *buf, int size, net_address **addr=0)      = 0;
32  virtual int get_fd()                                             = 0;
33  virtual ~net_socket()              { ; }
34  virtual void read_selectable()     { ; }
35  virtual void read_unselectable()   { ; }
36  virtual void write_selectable()    { ; }
37  virtual void write_unselectable()  { ; }
38  virtual int listen(int port)       { return 0; }
39  virtual net_socket *accept(net_address *&from) { from=0; return 0; }
40} ;
41
42class net_protocol
43{
44public :
45  enum debug_type
46    { DB_OFF,                // no debug printing
47      DB_MAJOR_EVENT,        // print major events
48      DB_IMPORTANT_EVENT,    // anything that would tell where a lockup occures
49      DB_MINOR_EVENT } ;     // anything you can think off
50
51private :
52  debug_type debug_setting;
53public :
54
55  enum connect_flags
56  { READ_WRITE,          // flags for connect to server
57                WRITE_ONLY } ;
58
59
60  int debug_level(debug_type min_level) { return min_level<=debug_setting; }
61  void set_debug_printing(debug_type level) { debug_setting=level; }
62
63  static net_protocol *first;
64  net_protocol *next;
65
66  virtual net_address *get_local_address() = 0;
67  virtual net_address *get_node_address(char *&server_name, int def_port, int force_port) = 0;
68  virtual net_socket *connect_to_server(net_address *addr,
69                                        net_socket::socket_type sock_type=net_socket::SOCKET_SECURE) =0;
70  virtual net_socket *create_listen_socket(int port, net_socket::socket_type sock_type) = 0;
71  virtual int installed() = 0;
72  virtual char *name() = 0;
73  virtual int select(int block) = 0;          // return # of sockets available for read & writing
74  virtual void cleanup() { ; }                // should do any needed pre-exit cleanup stuff
75  net_socket *connect_to_server(char *&server_name, int port, int force_port=0,
76                                net_socket::socket_type sock_type=net_socket::SOCKET_SECURE);
77
78        // Notification methods
79        virtual net_socket *start_notify(int port, void *data, int len) { return 0; }
80        virtual void end_notify() {}
81        // for protocols that don't know how to find address without help, start_notify creates
82        //   a fast/connectionless socket to respond to find address request packets.  After start_notify,
83        //   protocol::select should automatically forward the specified data to all requesters.
84        //   find_address should "broadcast" a notification request packet to all addresses it can
85        //   and wait for any responses
86
87        // Find methods
88  virtual net_address *find_address(int port, char *name) { return 0; }   // name should be a 256 byte buffer
89  virtual void reset_find_list() { ; }
90
91  net_protocol() { next=first; first=this; debug_setting=DB_OFF; }
92  virtual ~net_protocol() { cleanup(); }
93} ;
94
95#endif
96
97
98
99
100
101
102
103
104
Note: See TracBrowser for help on using the repository browser.