Starshatter_Open
Open source Starshatter engine
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
NetSock.h
Go to the documentation of this file.
1 /* Project nGenEx
2  Destroyer Studios LLC
3  Copyright © 1997-2004. All Rights Reserved.
4 
5  SUBSYSTEM: NetEx.lib
6  FILE: NetSock.h
7  AUTHOR: John DiCamillo
8 
9 
10  OVERVIEW
11  ========
12  Network (IP) Socket
13 */
14 
15 #ifndef NetSock_h
16 #define NetSock_h
17 
18 #include <windows.h>
19 #include "NetAddr.h"
20 #include "Text.h"
21 
22 // +-------------------------------------------------------------------+
23 
24 #define NET_MAX_TIMEOUT 1e9
25 
26 class NetSock
27 {
28 public:
29  static const char* TYPENAME() { return "NetSock"; }
30 
31  enum SELECT_TYPE {
34  };
35 
36  NetSock(bool stream=false);
37  NetSock(const NetAddr& addr, bool stream=false);
38  ~NetSock();
39 
40  int bind(const NetAddr& addr);
41  int connect(const NetAddr& addr);
42  int listen(int max_connections=5);
43  NetSock* accept(NetAddr* addr=0);
44  int available();
45  int send(Text msg);
46  Text recv();
47  int sendto(Text msg, const NetAddr& dest);
48  Text recvfrom(NetAddr* a=0);
50  long seconds=0, long microseconds=0);
51 
52  int shutdown_input();
53  int shutdown_output();
54  int set_timeout(int msecs);
55  int close();
56 
57  DWORD max_packet_size() const;
58  bool is_stream() const { return stream; }
59  bool is_closed() const { return closed; }
60  int status() const { return stat; }
61 
62 private:
63  NetSock(SOCKET s, bool stream);
64 
65  SOCKET s;
66  bool stream;
67  bool closed;
68  int stat;
69  int current_timeout;
70 };
71 
72 
73 #endif NetSock_h