]> git.evergreen-ils.org Git - Evergreen.git/blob - OpenSRF/src/libtransport/transport_socket.h
adding
[Evergreen.git] / OpenSRF / src / libtransport / transport_socket.h
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <sys/types.h>
4 #include <errno.h>
5
6 #include "utils.h"
7 #include "logging.h"
8 //---------------------------------------------------------------
9 // WIN32
10 //---------------------------------------------------------------
11 #ifdef WIN32
12 #include <Windows.h>
13 #include <Winsock.h>
14 #else
15
16 //---------------------------------------------------------------
17 // Unix headers
18 //---------------------------------------------------------------
19 #include <unistd.h>
20 #include <sys/time.h>
21 #include <sys/stat.h>
22 #include <fcntl.h>
23 #include <sys/socket.h>
24 #include <arpa/inet.h>
25 #include <netdb.h>
26 #include <netinet/in.h>
27 #endif
28
29 #ifndef TRANSPORT_SOCKET_H
30 #define TRANSPORT_SOCKET_H
31
32 /* how many characters we read from the socket at a time */
33 #ifdef _ROUTER
34 #define BUFSIZE 412
35 #else
36 #define BUFSIZE 4096
37 #endif
38
39 /* we maintain the socket information */
40 struct transport_socket_struct {
41         /* for a client, sock_fd is THE socket connection.  For a server,
42                 it's the socket we listen on */
43         int     sock_fd;
44         int     connected;
45         char* server; /* remote server name or ip */
46         int     port;
47         void* user_data;
48
49         /* user_data may be anything.  it's whatever you wish
50                 to see showing up in the callback in addition to
51                 the acutal character data*/
52         void (*data_received_callback) (void * user_data, char*);
53 };
54 typedef struct transport_socket_struct transport_socket;
55
56 /* connects.  If is_server is true, we call tcp_server_connect */
57 int tcp_connect( transport_socket* obj );
58
59 int tcp_send( transport_socket* obj, const char* data );
60
61 int tcp_disconnect( transport_socket* obj );
62
63 /* does both client and server waiting. 
64         returns the socket_fd on success, 0 on error */
65 int tcp_wait( transport_socket* obj, int timeout );
66
67 int tcp_connected(transport_socket* obj);
68
69
70
71 #endif