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