18 #define _usocket_hpp_ 1 19 #include <ubit/udefs.hpp> 20 #include <ubit/ustr.hpp> 67 USocket(
const char* remote_host,
int remote_port);
71 virtual int connect(
const char* remote_host,
int remote_port);
77 bool isConnected()
const {
return sock >= 0;}
80 int getRemotePort()
const {
return remport;}
81 int getDescriptor()
const {
return sock;}
83 bool sendBlock(
const char* buffer,
unsigned short size);
110 bool sendBytes(
const char* buffer,
unsigned int size);
128 struct sockaddr_in* sin;
182 bool bind(
int port,
int backlog = 0,
bool reuse_address =
true);
194 virtual void close();
203 int getLocalPort()
const {
return listen_port;}
206 int getDescriptor()
const {
return listen_sock;}
210 int listen_port, listen_sock;
211 struct sockaddr_in* sin;
223 const char* data()
const;
230 unsigned int size()
const;
231 unsigned int consumed()
const;
233 bool resize(
unsigned short);
234 bool augment(
unsigned short);
238 enum {DEFAULT_BUFSIZE = 512, AUGMENT_QUANTUM = 2048};
240 char default_buffer[DEFAULT_BUFSIZE];
241 unsigned int inpos, outpos;
242 unsigned int bufsize;
250 void writeChar(
char);
251 void writeChar(
unsigned char);
252 void writeShort(
short);
253 void writeLong(
long);
254 void writeString(
const UStr&);
255 void writeString(
const char*);
256 void writeString(
const char* s,
unsigned int len);
257 void writeEvent(
unsigned char event_type,
unsigned char event_flow,
258 long x,
long y,
unsigned long detail);
266 void readChar(
char&);
267 void readChar(
unsigned char&);
268 void readShort(
short&);
269 void readLong(
long&);
270 void readString(
UStr&);
271 void readEvent(
unsigned char& event_type,
unsigned char& event_flow,
272 long& x,
long& y,
unsigned long& detail);
bool sendBytes(const char *buffer, unsigned int size)
see receiveBytes().
Definition: usocket.cpp:228
virtual void onInput(UCall &)
adds a callback that is fired when data is received on the socket.
Definition: usocket.cpp:177
bool sendBlock(const char *buffer, unsigned short size)
see receiveBlock().
Definition: usocket.cpp:241
UInbuf (.
Definition: usocket.hpp:264
UIObuf (.
Definition: usocket.hpp:218
bool receiveBytes(char *buffer, unsigned int size)
byte oriented I/O.
Definition: usocket.cpp:261
UOutbuf (.
Definition: usocket.hpp:248
UServerSocket.
Definition: usocket.hpp:156
virtual USocket * createSocket() const
called by accept() to create the new socket (see accept() for details).
Definition: usocket.hpp:197
bool isClosed() const
returns the closed state of the ServerSocket
Definition: usocket.hpp:200
bool receiveBlock(UInbuf &)
simplified block oriented I/O.
Definition: usocket.cpp:301
base class of callback objects for firing functions or methods.
Definition: ucall.hpp:144
a USource object fires callbacks when a file or a socket gets data.
Definition: usource.hpp:35
Ubit Simple Sockets.
Definition: usocket.hpp:64
Definition: uhardfont.hpp:31
Ubit String.
Definition: ustr.hpp:72