分类:
2008-09-18 11:31:35
CODE:
struct ds_socket_pack
{
int socket_fd;
const char* address;
int port;
struct sockaddr_in s_in;
struct event* pevent;
} ;
typedef struct ds_socket_pack ds_socket_pack;
ds_socket_pack* ds_socket_init(const char* address, int port);
void ds_socket_free(ds_socket_pack*);
namespace ds_socket_tcp
{
int ds_socket_client_init(ds_socket_pack*);
int ds_socket_server_init(ds_socket_pack*);
void ds_socket_client_run(ds_socket_pack*, void (*)(int, short, void *));
void ds_socket_server_run(ds_socket_pack*, void (*)(int, short, void *));
void ds_socket_dispatch(ds_socket_pack*);
int ds_recv(int fd, char**, int size, ds_socket_pack* = 0, int time_out = 0);
int ds_send(int fd, const char*, int size, ds_socket_pack* = 0);
// for TCP, the last param is no useful
}
UDPCODE:
namespace ds_socket_udp
{
int ds_socket_server_init(ds_socket_pack* p);
int ds_socket_client_init(ds_socket_pack* p);
void ds_socket_client_run(ds_socket_pack*, void (*)(int, short, void *));
void ds_socket_server_run(ds_socket_pack*, void (*)(int, short, void *));
void ds_socket_dispatch(ds_socket_pack*);
int ds_recv(int fd, char**, int size, ds_socket_pack*, int time_out = 0);
int ds_send(int fd, const char*, int size, ds_socket_pack*);
}
.