ezsockets.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
#ifndef EZSOCKETS_H
00010
#define EZSOCKETS_H
00011
00012
#if defined(WITHOUT_NETWORKING)
00013
#error do not include ezsockets.h when WITHOUT_NETWORKING
00014
#endif
00015
00016
#include <sstream>
00017
#include <string>
00018
#include <vector>
00019
#include <fcntl.h>
00020
#include <ctype.h>
00021
#include "global.h"
00022
00023
#if defined(_XBOX)
00024
00025
00026
00027
00028
00029
#include <xtl.h>
00030
#elif defined(_WINDOWS)
00031
#include <winsock2.h>
00032
#else
00033
#include <netinet/in.h>
00034
#endif
00035
00036
using namespace std;
00037
00038 class EzSockets
00039 {
00040
public:
00041
00042
EzSockets();
00043
~EzSockets();
00044
00045
00046
bool create();
00047
bool create(
int Protocol);
00048
bool create(
int Protocol,
int Type);
00049
00050
00051
bool bind(
unsigned short port);
00052
00053
00054
bool listen();
00055
00056
00057
bool accept(
EzSockets &socket);
00058
00059
00060
bool connect(
const string& host,
unsigned short port);
00061
00062
00063
void close();
00064
00065
00066
bool check();
00067
00068
long uAddr();
00069
00070
bool CanRead();
00071
bool IsError();
00072
bool CanWrite();
00073
00074
void update();
00075
00076
00077
void SendData(
const string& outData);
00078
void SendData(
const char *data,
unsigned int bytes);
00079
int ReadData(
char *data,
unsigned int bytes);
00080
int PeekData(
char *data,
unsigned int bytes);
00081
00082
00083
void SendPack(
const char *data,
unsigned int bytes);
00084
int ReadPack(
char *data,
unsigned int max);
00085
int PeekPack(
char *data,
unsigned int max);
00086
00087
00088
void SendStr(
const string& data,
char delim =
'\0');
00089
int ReadStr(string& data,
char delim =
'\0');
00090
int PeekStr(string& data,
char delim =
'\0');
00091
00092
00093
00094
char operator[] (
int i);
00095
friend istream&
operator>>(istream& is,
EzSockets& obj);
00096
friend ostream&
operator<<(ostream& os,
const EzSockets& obj);
00097
00098 bool blocking;
00099 enum SockState
00100 {
00101
skDISCONNECTED = 0,
00102
skUNDEF1,
00103
skLISTENING,
00104
skUNDEF3,
00105
skUNDEF4,
00106
skUNDEF5,
00107
skUNDEF6,
00108
skCONNECTED,
00109
skERROR
00110 };
00111 struct sockaddr_in fromAddr;
00112 unsigned long fromAddr_len;
00113
00114
00115 string
inBuffer;
00116 string
outBuffer;
00117
00118
int pUpdateWrite();
00119
int pUpdateRead();
00120
00121
int pReadData(
char * data);
00122
int pWriteData(
const char * data,
int dataSize);
00123
00124 SockState state;
00125
00126 int lastCode;
00127
00128 CString address;
00129
00130
private:
00131
00132
00133
#if defined(_WINDOWS) || defined(_XBOX)
00134
WSADATA wsda;
00135
#endif
00136
00137 int MAXCON;
00138 int sock;
00139 struct sockaddr_in addr;
00140
00141
00142
00143 fd_set *
scks;
00144 timeval *
times;
00145
00146
00147 };
00148
00149 istream&
operator>>(istream& is,
EzSockets& obj);
00150 ostream&
operator<<(ostream& os,
EzSockets& obj);
00151
00152
00153
#endif
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
Generated on Thu Jan 27 20:57:20 2005 for StepMania by
1.3.7