00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef _GLASS_PROTOCOL_UDP_HH_
00022 #define _GLASS_PROTOCOL_UDP_HH_
00023
00024 #include <map>
00025
00026 #if !defined(_MSC_VER)
00027 # include <netinet/in.h>
00028 #endif
00029
00030 namespace libglass {
00031
00032 class LIBGLASS_API UDP : public Protocol {
00033 private:
00034
00035
00036 unsigned int writePacket(nodeFD fd, unsigned char *m,
00037 unsigned int length, struct sockaddr_in *addr);
00038
00039 protected:
00041 #if defined(_MSC_VER) && (_MSC_VER < 1300) // earlier than .NET compiler (VC 7.0)
00042
00043
00044 enum{ default_connect_port = 9192 };
00045 enum{ default_comm_port = 9193 };
00046 #else
00047 static const unsigned int default_connect_port = 9192;
00048 static const unsigned int default_comm_port = 9193;
00049 #endif
00050
00051 unsigned int comm_port;
00052
00054 struct server_struct {
00055 int sockfd;
00057 std::map<nodeFD, struct nodedata *>
00058 clients;
00059 } server;
00060 struct client_struct {
00061 int sockfd;
00062 struct sockaddr_in
00063 address;
00064 } client;
00065
00066 PacketLog *plog;
00067
00068 int _listen(unsigned int port);
00069 nodeFD _accept(void);
00070 nodeFD _connect(const char *host, unsigned int port);
00071 void _disconnect(nodeFD node);
00072 bool _send(Packet &p);
00073 int _recv(Packet &p);
00074 public:
00075 UDP();
00076 ~UDP();
00077
00078 };
00079
00080
00081 }
00082
00083 #endif // _GLASS_PROTOCOL_UDP_HH_