00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
#ifndef __GI_TCP_H
00018
#define __GI_TCP_H
00019
00020
00021
00032
00033
00034
#include "fdbuf.h"
00035
#include "array.h"
00036
00037
00038
00039 EXTERN_C_BEGIN
00040
00041
00042
00043
typedef enum
00044 {
00045 GI_TCP_INCOMING,
00046 GI_TCP_OUTGOING
00047 } gi_tcp_direction_t;
00048
00052 typedef struct gi_tcp
00053 {
00057 int fd;
00058 gi_tcp_direction_t
dir;
00060
struct
00061
{
00062 unsigned int in;
00063 unsigned int out;
00064 } stats;
00065
00069 FDBuf *
buf;
00070 void *
udata;
00075 Array *
wqueue;
00076 gi_input_t
wqueue_id;
00078 struct sockaddr_in peer;
00079 size_t peer_len;
00080 }
GiTcp;
00081
00082
00083
00088 LIBGIFT_EXPORT
00089
int gi_tcpsock_connect (in_addr_t host, in_port_t port,
bool blocking);
00090
00094 LIBGIFT_EXPORT
00095
int gi_tcpsock_accept (
int fd,
bool blocking);
00096
00100 LIBGIFT_EXPORT
00101
int gi_tcpsock_bind (in_port_t port,
bool blocking);
00102
00103
00104
00110 LIBGIFT_EXPORT
00111
GiTcp *gi_tcp_wrap (
int fd, gi_tcp_direction_t direction,
void *udata);
00112
00118 LIBGIFT_EXPORT
00119
void gi_tcp_unwrap (
GiTcp *gitcp);
00120
00121
00122
00127 LIBGIFT_EXPORT
00128
GiTcp *gi_tcp_open (in_addr_t host, in_port_t port,
bool blocking);
00129
00134 LIBGIFT_EXPORT
00135
GiTcp *gi_tcp_accept (
GiTcp *gitcp,
bool blocking);
00136
00140 LIBGIFT_EXPORT
00141
GiTcp *gi_tcp_bind (in_port_t port,
bool blocking);
00142
00148 LIBGIFT_EXPORT
00149
void gi_tcp_close (
GiTcp *gitcp);
00150
00151
00152
00165 LIBGIFT_EXPORT
00166
unsigned int gi_tcp_flush (
GiTcp *gitcp);
00167
00168
00169
00174 LIBGIFT_EXPORT
00175
int gi_tcp_send (
GiTcp *gitcp,
const void *buf, size_t len);
00176
00185 LIBGIFT_EXPORT
00186
int gi_tcp_write (
GiTcp *gitcp,
const void *buf, size_t len);
00187
00188
00189
00194 LIBGIFT_EXPORT
00195
int gi_tcp_recv (
GiTcp *gitcp,
void *buf, size_t len);
00196
00200 LIBGIFT_EXPORT
00201
int gi_tcp_peek (
GiTcp *gitcp,
void *buf, size_t len);
00202
00203
00204
00210 LIBGIFT_EXPORT
00211
int gi_tcp_err (
GiTcp *gitcp);
00212
00213
00214
00219 LIBGIFT_EXPORT
00220
FDBuf *gi_tcp_readbuf (
GiTcp *gitcp);
00221
00225 LIBGIFT_EXPORT
00226
int gi_tcp_fd (
GiTcp *gitcp);
00227
00231 LIBGIFT_EXPORT
00232 in_addr_t gi_tcp_addr (
GiTcp *gitcp);
00233
00237 LIBGIFT_EXPORT
00238 in_port_t gi_tcp_port (
GiTcp *gitcp);
00239
00246 LIBGIFT_EXPORT
00247
char *gi_tcp_addrstr (
GiTcp *gitcp);
00248
00258 LIBGIFT_EXPORT
00259
char *gi_tcp_addrstr_r (
GiTcp *gitcp,
char *buf, size_t len);
00260
00261
00262
00263 EXTERN_C_END
00264
00265
00266
00267
#endif