~ubuntu-branches/ubuntu/gutsy/psqlodbc/gutsy

« back to all changes in this revision

Viewing changes to socket.h

  • Committer: Bazaar Package Importer
  • Author(s): Martin Pitt
  • Date: 2004-05-13 10:47:36 UTC
  • Revision ID: james.westby@ubuntu.com-20040513104736-a530gmn0p3knep89
Tags: upstream-07.03.0200
ImportĀ upstreamĀ versionĀ 07.03.0200

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
#endif
 
30
#define INADDR_NONE ((in_addr_t)-1)
 
31
#endif
 
32
 
 
33
#else
 
34
#include <winsock.h>
 
35
#define SOCKETFD SOCKET
 
36
#endif
 
37
 
 
38
#define SOCKET_ALREADY_CONNECTED                        1
 
39
#define SOCKET_HOST_NOT_FOUND                           2
 
40
#define SOCKET_COULD_NOT_CREATE_SOCKET          3
 
41
#define SOCKET_COULD_NOT_CONNECT                        4
 
42
#define SOCKET_READ_ERROR                                       5
 
43
#define SOCKET_WRITE_ERROR                                      6
 
44
#define SOCKET_NULLPOINTER_PARAMETER            7
 
45
#define SOCKET_PUT_INT_WRONG_LENGTH                     8
 
46
#define SOCKET_GET_INT_WRONG_LENGTH                     9
 
47
#define SOCKET_CLOSED                                           10
 
48
 
 
49
 
 
50
struct SocketClass_
 
51
{
 
52
 
 
53
        int                     buffer_size;
 
54
        int                     buffer_filled_in;
 
55
        int                     buffer_filled_out;
 
56
        int                     buffer_read_in;
 
57
        unsigned char *buffer_in;
 
58
        unsigned char *buffer_out;
 
59
 
 
60
        SOCKETFD        socket;
 
61
 
 
62
        char       *errormsg;
 
63
        int                     errornumber;
 
64
        struct sockaddr_in      sadr; /* Used for handling connections for cancel */
 
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 ? self->errornumber : SOCKET_CLOSED)
 
77
#define SOCK_get_errmsg(self)   (self ? self->errormsg : "socket closed")
 
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