]> granicus.if.org Git - postgresql/blob - src/interfaces/odbc/socket.h
Provide some initial support for building the ODBC driver for
[postgresql] / src / interfaces / odbc / socket.h
1 /* File:                        socket.h
2  *
3  * Description:         See "socket.c"
4  *
5  * Comments:            See "notice.txt" for copyright and license information.
6  *
7  */
8
9 #ifndef __SOCKET_H__
10 #define __SOCKET_H__
11
12 #include "psqlodbc.h"
13
14 #ifndef WIN32
15 #include <sys/types.h>
16 #include <sys/socket.h>
17 #include <unistd.h>
18 #include <netdb.h>
19 #include <netinet/in.h>
20 #include <arpa/inet.h>
21
22 #define closesocket(xxx) close(xxx)
23 #define SOCKETFD int
24
25 #ifndef           INADDR_NONE
26 #ifndef _IN_ADDR_T
27 #define _IN_ADDR_T
28 typedef unsigned int in_addr_t;
29
30 #endif
31 #define INADDR_NONE ((in_addr_t)-1)
32 #endif
33
34 #else
35 #include <winsock.h>
36 #define SOCKETFD SOCKET
37 #endif
38
39 #define SOCKET_ALREADY_CONNECTED                        1
40 #define SOCKET_HOST_NOT_FOUND                           2
41 #define SOCKET_COULD_NOT_CREATE_SOCKET          3
42 #define SOCKET_COULD_NOT_CONNECT                        4
43 #define SOCKET_READ_ERROR                                       5
44 #define SOCKET_WRITE_ERROR                                      6
45 #define SOCKET_NULLPOINTER_PARAMETER            7
46 #define SOCKET_PUT_INT_WRONG_LENGTH                     8
47 #define SOCKET_GET_INT_WRONG_LENGTH                     9
48 #define SOCKET_CLOSED                                           10
49
50
51 struct SocketClass_
52 {
53
54         int                     buffer_size;
55         int                     buffer_filled_in;
56         int                     buffer_filled_out;
57         int                     buffer_read_in;
58         unsigned char *buffer_in;
59         unsigned char *buffer_out;
60
61         SOCKETFD        socket;
62
63         char       *errormsg;
64         int                     errornumber;
65
66         char            reverse;                /* used to handle Postgres 6.2 protocol
67                                                                  * (reverse byte order) */
68
69 };
70
71 #define SOCK_get_char(self)             (SOCK_get_next_byte(self))
72 #define SOCK_put_char(self, c)  (SOCK_put_next_byte(self, c))
73
74
75 /* error functions */
76 #define SOCK_get_errcode(self)          (self->errornumber)
77 #define SOCK_get_errmsg(self)           (self->errormsg)
78
79
80 /* Socket prototypes */
81 SocketClass *SOCK_Constructor(const ConnectionClass *conn);
82 void            SOCK_Destructor(SocketClass *self);
83 char            SOCK_connect_to(SocketClass *self, unsigned short port, char *hostname);
84 void            SOCK_get_n_char(SocketClass *self, char *buffer, int len);
85 void            SOCK_put_n_char(SocketClass *self, char *buffer, int len);
86 BOOL            SOCK_get_string(SocketClass *self, char *buffer, int bufsize);
87 void            SOCK_put_string(SocketClass *self, char *string);
88 int                     SOCK_get_int(SocketClass *self, short len);
89 void            SOCK_put_int(SocketClass *self, int value, short len);
90 void            SOCK_flush_output(SocketClass *self);
91 unsigned char SOCK_get_next_byte(SocketClass *self);
92 void            SOCK_put_next_byte(SocketClass *self, unsigned char next_byte);
93 void            SOCK_clear_error(SocketClass *self);
94
95 #endif