net_prot.hh 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. /********************************************************************** <BR>
  2. This file is part of Crack dot Com's free source code release of
  3. Golgotha. <a href="http://www.crack.com/golgotha_release"> <BR> for
  4. information about compiling & licensing issues visit this URL</a>
  5. <PRE> If that doesn't help, contact Jonathan Clark at
  6. golgotha_source@usa.net (Subject should have "GOLG" in it)
  7. ***********************************************************************/
  8. #ifndef I4_NET_PROTOCOL_HH
  9. #define I4_NET_PROTOCOL_HH
  10. #include "string/string.hh"
  11. // The network protocol is the interface to all the network commands.
  12. // Multiple network interfaces such as TCPIP and IPX can exsist at the same time
  13. // and you don't really have to know which one you are using.
  14. class i4_net_address; // defined in network/net_addr.hh
  15. class i4_notifier_socket; // defined in network/net_find.hh
  16. class i4_finder_socket; // defined in network/net_find.hh
  17. class i4_net_socket; // defined in network/net_sock.hh
  18. class i4_net_address; // defined in network/net_addr.hh
  19. enum i4_protocol_type { I4_TCPIP }; // this is the only kind we have support for right now
  20. enum i4_socket_type { I4_PACKETED_DATA, // data is sent in packets (i.e. udp)
  21. I4_CONTINOUS_STREAM }; // data is seen as a continous stream
  22. class i4_net_protocol
  23. {
  24. public:
  25. static i4_net_protocol *first; // protocols are kept in a list
  26. i4_net_protocol *next;
  27. i4_net_protocol();
  28. virtual char *name() = 0; // for debugging
  29. virtual i4_protocol_type type() = 0;
  30. // this creates a socket that will notify other clients that this server
  31. // exsist if the create a finder socket.
  32. virtual i4_notifier_socket *create_notifier_socket(int port,
  33. const i4_const_str &notification_string) = 0;
  34. // this socket will look for other server on the poll_port
  35. // implemented as spurious broadcast packets.
  36. virtual i4_finder_socket *create_finder_socket(int poll_port, int listen_port) = 0;
  37. // for TCPIP this converts an internet name to an IP address
  38. virtual i4_net_address *name_to_address(const i4_const_str &name) = 0;
  39. // try to make a connection to a remote server
  40. virtual i4_net_socket *connect(i4_net_address *addr,
  41. i4_socket_type type=I4_CONTINOUS_STREAM) = 0;
  42. // creates a socket that listens to a port, see network/net_sock.hh
  43. virtual i4_net_socket *listen(int port,
  44. i4_socket_type type=I4_CONTINOUS_STREAM) = 0;
  45. // timeout=0 is inifinity, returns number of sockets with events pending
  46. virtual int select(int milli_sec_timeout) = 0;
  47. };
  48. inline i4_net_protocol *i4_get_first_protocol() { return i4_net_protocol::first; }
  49. i4_net_protocol *i4_get_typed_protocol(i4_protocol_type type=I4_TCPIP);
  50. #endif