Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef UDPRAW_H
00020 #define UDPRAW_H
00021
00022 #include "udpraw_api.h"
00023 #include <string>
00024 #include <vector>
00025 #ifdef _MSC_VER
00026
00027 #include <winsock2.h>
00028 #else
00029 #include <netinet/in.h>
00030 #endif
00031
00039 class UDPRAW_API Udpraw {
00040 private:
00041
00042 protected:
00043
00044 #ifdef _MSC_VER
00045 WSADATA wsaData;
00046 SOCKET recvSocket,
00047 sendSocket;
00048 bool initWSA;
00049 #else
00050 int recvSocket,
00051 sendSocket;
00052 #endif
00053
00054 bool createdRecv,
00055 createdSend;
00057 fd_set readSocks;
00058 fd_set writeSocks;
00059 fd_set exceptionSocks;
00060 int numSocksReadable;
00062 sockaddr_in recvAddr,
00063 sendAddr,
00064 fromAddr;
00066 std::vector <std::string> sendIp;
00067 std::vector<int>::iterator recv_port_iterator;
00068 std::vector <int> sendPort;
00070
00071 int statSent;
00072 int statRecvd;
00074 int lastError;
00075 std::string errorPrepend;
00077 struct {
00078 float send;
00079 float recv;
00080 } simulateLoss;
00082 void init();
00083 bool simulatePacketLoss(float prob);
00086 public:
00087
00089 enum UdprawError {
00090 UDPRAW_NO_ERROR,
00091 UDPRAW_BIND,
00092 UDPRAW_MSGSIZE,
00093 UDPRAW_NOINIT,
00094 UDPRAW_NOIP,
00095 UDPRAW_NOPORT,
00096 UDPRAW_RECV,
00097 UDPRAW_SELECT,
00098 UDPRAW_SEND,
00099 UDPRAW_SOCKEXCEPTION,
00100 UDPRAW_UNMATCHED
00101 };
00102
00103
00104 Udpraw();
00105 ~Udpraw();
00108 int getError();
00109 std::string getErrorStr();
00110 std::string getErrorStr(int error);
00111 void writeError();
00112 void writeError(std::string prependMsg);
00113 void writeError(int error);
00116
00117
00118
00119
00120
00121
00122 int initReceiver(int port);
00123 void initSender(int port = 0);
00124 void initSender(const char* ip, int port = 0);
00125 void initSender(std::vector <std::string> ip_list, int port = 0);
00126 void initSender(std::vector <std::string> ip_list, std::vector <int> port_list);
00129
00130
00131
00132
00133
00134
00135 void setSendIp(const char* ip);
00136 void setSendIp(std::vector <std::string> ip_list);
00137 void setSendPort(int port);
00138 void setSendPort(std::vector <int> port_list);
00151 int doSelect();
00152
00169 int recvRaw(char* buf, int len, bool select = true);
00170
00185 int sendRaw(const char* buf, int len, bool select = true);
00186
00187
00188 int getStatSent();
00189 int getStatRecvd();
00190 void setStatSent(int bytes);
00191 void setStatRecvd(int bytes);
00194 void setSimulateLossSend(float probabilityofloss);
00195 void setSimulateLossRecv(float probabilityofloss);
00196 float getSimulateLossSend();
00197 float getSimulateLossRecv();
00200 int closeAndCleanup();
00202 };
00203
00204 #endif