1
/* Copyright (C) 2007 MySQL AB
3
This program is free software; you can redistribute it and/or modify
4
it under the terms of the GNU General Public License as published by
5
the Free Software Foundation; version 2 of the License.
7
This program is distributed in the hope that it will be useful,
8
but WITHOUT ANY WARRANTY; without even the implied warranty of
9
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10
GNU General Public License for more details.
12
You should have received a copy of the GNU General Public License
13
along with this program; if not, write to the Free Software
14
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
16
#ifndef _NETWORK_SOCKET_H_
17
#define _NETWORK_SOCKET_H_
23
#ifdef HAVE_SYS_TIME_H
25
* event.h needs struct timeval and doesn't include sys/time.h itself
30
#include <sys/types.h> /** u_char */
32
#include <sys/socket.h> /** struct sockaddr */
34
#ifdef HAVE_NETINET_IN_H
35
#include <netinet/in.h> /** struct sockaddr_in */
37
#include <netinet/tcp.h>
40
#include <sys/un.h> /** struct sockaddr_un */
43
* use closesocket() to close sockets to be compatible with win32
45
#define closesocket(x) close(x)
54
/* a input or output stream */
58
size_t len; /* len in all chunks */
59
size_t offset; /* offset over all chunks */
64
struct sockaddr_in ipv4;
66
struct sockaddr_un un;
68
struct sockaddr common;
77
int fd; /**< socket-fd */
78
struct event event; /**< events for this fd */
82
guint32 packet_len; /**< the packet_len is a 24bit unsigned int */
83
guint8 packet_id; /**< id which increments for each packet in the stream */
86
network_queue *recv_queue;
87
network_queue *send_queue;
89
GString *header; /** raw buffer for the packet_len and packet_id */
94
* data extracted from the handshake
96
* all server-side only
98
guint32 mysqld_version; /**< numberic version of the version string */
99
guint32 thread_id; /**< connection-id, set in the handshake packet */
100
GString *scramble_buf; /**< the 21byte scramble-buf */
101
GString *username; /**< username of the authed connection */
102
GString *scrambled_password; /**< scrambled_pass used to auth */
105
* store the auth-handshake packet to simulate a login
107
GString *auth_handshake_packet;
108
int is_authed; /** did a client already authed this connection */
111
* store the default-db of the socket
113
* the client might have a different default-db than the server-side due to
114
* statement balancing
116
GString *default_db; /** default-db of this side of the connection */
120
network_queue *network_queue_init(void);
121
void network_queue_free(network_queue *queue);
122
int network_queue_append(network_queue *queue, const char *data, size_t len, int packet_id);
123
int network_queue_append_chunk(network_queue *queue, GString *chunk);
125
network_socket *network_socket_init(void);
126
void network_socket_free(network_socket *s);