Commit d5fe1db8 authored by monty@hundin.mysql.fi's avatar monty@hundin.mysql.fi

One should not only have to include my_net.h to work with sockets.

This wrapper noew will include all the necessary, system specific files,
which makes all normal source files much easier to write and maintain.
Portability fixes.
parent 196f620e
......@@ -8903,7 +8903,13 @@ version 4.0;
@item
The old C API functions @code{mysql_drop_db}, @code{mysql_create_db} and
@code{mysql_connect} are not supported anymore, unless one compiles
MySQL with @code{USE_OLD_FUNCTIONS}.
MySQL with @code{USE_OLD_FUNCTIONS}. Instead of doing this, one should
change the client to use the new 4.0 API.
@item
In the @code{MYSQL_FIELD} structure, @code{length} and @code{max_length} has
changed from @code{unsigned int} to @code{unsigned long}. This should not
cause any other problems than some warnings if you use these to
@code{printf()} type function.
@item
You should use @code{TRUNCATE TABLE} when you want to delete all rows
from a table and you don't care of how many rows where deleted.
......@@ -928,7 +928,7 @@ static void print_header(MYSQL_RES *result)
putchar('|');
while ((field = mysql_fetch_field(result)))
{
printf(" %-*s|",field->max_length+1,field->name);
printf(" %-*s|",(int) field->max_length+1,field->name);
}
putchar('\n');
print_top(result);
......@@ -983,11 +983,11 @@ static void print_relative_row(MYSQL_RES *result, MYSQL_ROW cur, uint row)
mysql_field_seek(result, 0);
field = mysql_fetch_field(result);
printf("| %-*s|", field->max_length + 1, cur[0]);
printf("| %-*s|", (int) field->max_length + 1, cur[0]);
field = mysql_fetch_field(result);
tmp = cur[1] ? strtoull(cur[1], NULL, 0) : (ulonglong) 0;
printf(" %-*s|\n", field->max_length + 1,
printf(" %-*s|\n", (int) field->max_length + 1,
llstr((tmp - last_values[row]), buff));
last_values[row] = tmp;
}
......
......@@ -713,7 +713,7 @@ static void print_res_header(MYSQL_RES *result)
putchar('|');
while ((field = mysql_fetch_field(result)))
{
printf(" %-*s|",field->max_length+1,field->name);
printf(" %-*s|",(int) field->max_length+1,field->name);
}
putchar('\n');
print_res_top(result);
......
......@@ -20,16 +20,11 @@
#define RESOLVE_VERSION "2.0"
#include <my_global.h>
#include <sys/types.h>
#include <sys/socket.h>
#ifndef HAVE_BROKEN_NETINET_INCLUDES
#include <netinet/in.h>
#endif
#include <arpa/inet.h>
#include <netdb.h>
#include <m_ctype.h>
#include <my_net.h>
#include <my_sys.h>
#include <m_string.h>
#include <netdb.h>
#include <getopt.h>
#if !defined(_AIX) && !defined(HAVE_UNIXWARE7_THREADS) && !defined(HAVE_UNIXWARE7_POSIX) && !defined(h_errno)
......
......@@ -653,6 +653,7 @@ typedef off_t os_off_t;
#define socket_errno WSAGetLastError()
#define SOCKET_EINTR WSAEINTR
#define SOCKET_EAGAIN WSAEINPROGRESS
#define SOCKET_EWOULDBLOCK WSAEINPROGRESS
#define SOCKET_ENFILE ENFILE
#define SOCKET_EMFILE EMFILE
#elif defined(OS2)
......
......@@ -15,14 +15,20 @@
Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA */
/* thread safe version of some common functions */
/*
thread safe version of some common functions:
my_inet_ntoa
/* for thread safe my_inet_ntoa */
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
This file is also used to make handling of sockets and ioctl()
portable accross systems.
#if !defined(MSDOS) && !defined(__WIN__) && !defined(__BEOS__)
*/
#ifndef _my_net_h
#define _my_net_h
C_MODE_START
#include <errno.h>
#ifdef HAVE_SYS_SOCKET_H
#include <sys/socket.h>
#endif
......@@ -32,10 +38,35 @@ extern "C" {
#ifdef HAVE_ARPA_INET_H
#include <arpa/inet.h>
#endif
#endif /* !defined(MSDOS) && !defined(__WIN__) */
#ifdef HAVE_POLL
#include <sys/poll.h>
#endif
#ifdef HAVE_SYS_IOCTL_H
#include <sys/ioctl.h>
#endif
#if !defined(MSDOS) && !defined(__WIN__) && !defined(HAVE_BROKEN_NETINET_INCLUDES) && !defined(__BEOS__)
#include <netinet/in_systm.h>
#include <netinet/in.h>
#include <netinet/ip.h>
#if !defined(alpha_linux_port)
#include <netinet/tcp.h>
#endif
#endif
#if defined(__EMX__)
#include <sys/ioctl.h>
#define ioctlsocket(A,B,C) ioctl((A),(B),(void *)(C),sizeof(*(C)))
#undef HAVE_FCNTL
#endif /* defined(__EMX__) */
#if defined(MSDOS) || defined(__WIN__)
#define O_NONBLOCK 1 /* For emulation of fcntl() */
#endif
/* Thread safe or portable version of some functions */
void my_inet_ntoa(struct in_addr in, char *buf);
#ifdef __cplusplus
}
C_MODE_END
#endif
......@@ -203,7 +203,7 @@ typedef struct st_udf_init
{
my_bool maybe_null; /* 1 if function can return NULL */
unsigned int decimals; /* for real functions */
unsigned int max_length; /* For string functions */
unsigned long max_length; /* For string functions */
char *ptr; /* free pointer for function data */
my_bool const_item; /* 0 if result is independent of arguments */
} UDF_INIT;
......
......@@ -31,16 +31,16 @@
#include <winsock.h>
#endif
#include <my_global.h>
#include "mysql_embed.h"
#include <mysql.h>
#include <mysql_embed.h>
#include <mysql_com.h>
#include <violite.h>
#include <mysqld_error.h>
#include <my_sys.h>
#include <m_string.h>
#include "mysql.h"
#include "mysqld_error.h"
#include <my_net.h>
#include <violite.h>
#include <signal.h>
#include <errno.h>
#include <sys/types.h>
#ifdef MYSQL_SERVER
ulong max_allowed_packet=65536;
......@@ -60,20 +60,9 @@ ulong net_write_timeout= NET_WRITE_TIMEOUT;
#endif
ulong net_buffer_length=8192; /* Default length. Enlarged if necessary */
#if !defined(__WIN__) && !defined(MSDOS)
#include <sys/socket.h>
#else
#if defined(__WIN__) || defined(MSDOS)
#undef MYSQL_SERVER /* Win32 can't handle interrupts */
#endif
#if !defined(MSDOS) && !defined(__WIN__) && !defined(HAVE_BROKEN_NETINET_INCLUDES) && !defined(__BEOS__)
#include <netinet/in_systm.h>
#include <netinet/in.h>
#include <netinet/ip.h>
#if !defined(alpha_linux_port)
#include <netinet/tcp.h>
#endif
#endif
#include "mysqld_error.h"
#ifdef MYSQL_SERVER
#include "my_pthread.h"
#include "thr_alarm.h"
......
......@@ -26,7 +26,7 @@
#include "mysql_embed.h"
#include "mysql.h"
#ifndef HAVE_VIO /* is Vio suppored by the Vio lib ? */
#ifndef HAVE_VIO /* is Vio enabled */
#include <errno.h>
#include <my_sys.h>
......@@ -37,27 +37,6 @@
#include <dbug.h>
#include <assert.h>
#if defined(__EMX__)
#include <sys/ioctl.h>
#define ioctlsocket(A,B,C) ioctl((A),(B),(void *)(C),sizeof(*(C)))
#undef HAVE_FCNTL
#endif /* defined(__EMX__) */
#if defined(MSDOS) || defined(__WIN__)
#ifdef __WIN__
#undef errno
#undef EINTR
#undef EAGAIN
#define errno WSAGetLastError()
#define EINTR WSAEINTR
#define EAGAIN WSAEINPROGRESS
#endif /* __WIN__ */
#define O_NONBLOCK 1 /* For emulation of fcntl() */
#endif
#ifndef EWOULDBLOCK
#define EWOULDBLOCK EAGAIN
#endif
#ifndef __WIN__
#define HANDLE void *
#endif
......@@ -72,14 +51,11 @@ struct st_vio
struct sockaddr_in remote; /* Remote internet address */
enum enum_vio_type type; /* Type of connection */
char desc[30]; /* String description */
/* #ifdef EMBEDDED_LIBRARY */
/* void *dest_net; */
void *dest_thd;
char *packets, **last_packet;
char *where_in_packet, *end_of_packet;
my_bool reading;
MEM_ROOT root;
/* #endif */
};
/* Initialize the communication buffer */
......@@ -90,7 +66,7 @@ Vio *vio_new(my_socket sd, enum enum_vio_type type, my_bool localhost)
vio = (Vio *) my_malloc (sizeof(*vio),MYF(MY_WME|MY_ZEROFILL));
if (vio)
{
init_alloc_root(&vio->root, 8192, 1024);
init_alloc_root(&vio->root, 8192, 8192);
vio->root.min_malloc = sizeof(char *) + 4;
vio->last_packet = &vio->packets;
}
......@@ -126,7 +102,7 @@ void vio_reset(Vio *vio)
int vio_errno(Vio *vio __attribute__((unused)))
{
return errno; /* On Win32 this mapped to WSAGetLastError() */
return socket_errno; /* On Win32 this mapped to WSAGetLastError() */
}
int vio_read(Vio * vio, gptr buf, int size)
......@@ -198,8 +174,9 @@ int vio_keepalive(Vio* vio, my_bool set_keep_alive)
my_bool
vio_should_retry(Vio * vio __attribute__((unused)))
{
int en = errno;
return en == EAGAIN || en == EINTR || en == EWOULDBLOCK;
int en = socket_errno;
return (en == SOCKET_EAGAIN || en == SOCKET_EINTR ||
en == SOCKET_EWOULDBLOCK);
}
......
......@@ -27,7 +27,7 @@ drop database foo;
drop database if exists foo;
flush tables with read lock;
create database foo;
Can't execute the query because you have a conflicting read lock
Got one of the listed errors
unlock tables;
create database foo;
show databases;
......@@ -37,7 +37,7 @@ mysql
test
flush tables with read lock;
drop database foo;
Can't execute the query because you have a conflicting read lock
Got one of the listed errors
unlock tables;
drop database foo;
show databases;
......
......@@ -13,7 +13,7 @@ Unknown table 'not_existing_database' in field list
select count(not_existing_database.t1.a) from t1;
Unknown table 'not_existing_database.t1' in field list
select count(not_existing_database.t1.a) from not_existing_database.t1;
Table 'not_existing_database.t1' doesn't exist
Got one of the listed errors
select 1 from t1 order by 2;
Unknown column '2' in 'order clause'
select 1 from t1 group by 2;
......
......@@ -48,7 +48,7 @@ id parent_id level
15 102 2
update t1 set id=id+1000;
update t1 set id=1024 where id=1009;
Duplicate entry '1024' for key 1
Got one of the listed errors
select * from t1;
id parent_id level
1001 100 0
......
drop database AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA;
Incorrect database name 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA'
Got one of the listed errors
......@@ -31,16 +31,16 @@
#include <winsock.h>
#endif
#include <my_global.h>
#include "mysql_embed.h"
#include <mysql.h>
#include <mysql_embed.h>
#include <mysql_com.h>
#include <violite.h>
#include <mysqld_error.h>
#include <my_sys.h>
#include <m_string.h>
#include "mysql.h"
#include "mysqld_error.h"
#include <my_net.h>
#include <violite.h>
#include <signal.h>
#include <errno.h>
#include <sys/types.h>
#ifdef MYSQL_SERVER
ulong max_allowed_packet=65536;
......@@ -60,20 +60,9 @@ ulong net_write_timeout= NET_WRITE_TIMEOUT;
#endif
ulong net_buffer_length=8192; /* Default length. Enlarged if necessary */
#if !defined(__WIN__) && !defined(MSDOS)
#include <sys/socket.h>
#else
#if defined(__WIN__) || defined(MSDOS)
#undef MYSQL_SERVER /* Win32 can't handle interrupts */
#endif
#if !defined(MSDOS) && !defined(__WIN__) && !defined(HAVE_BROKEN_NETINET_INCLUDES) && !defined(__BEOS__)
#include <netinet/in_systm.h>
#include <netinet/in.h>
#include <netinet/ip.h>
#if !defined(alpha_linux_port)
#include <netinet/tcp.h>
#endif
#endif
#include "mysqld_error.h"
#ifdef MYSQL_SERVER
#include "my_pthread.h"
#include "thr_alarm.h"
......
......@@ -25,22 +25,10 @@
#include <my_global.h>
#include <mysql_com.h>
#include <violite.h>
#include <errno.h>
#include <assert.h>
#include <my_sys.h>
#include <my_net.h>
#include <m_string.h>
#ifdef HAVE_POLL
#include <sys/poll.h>
#endif
#ifdef HAVE_SYS_IOCTL_H
#include <sys/ioctl.h>
#endif
#if defined(__EMX__) || defined(OS2)
#define ioctlsocket ioctl
#endif /* defined(__EMX__) */
/*
* Helper to fill most of the Vio* with defaults.
......
......@@ -27,36 +27,10 @@
#include <mysql_com.h>
#include <errno.h>
#include <assert.h>
#include <violite.h>
#include <my_sys.h>
#include <my_net.h>
#include <m_string.h>
#ifdef HAVE_POLL
#include <sys/poll.h>
#endif
#ifdef HAVE_SYS_IOCTL_H
#include <sys/ioctl.h>
#endif
#if !defined(MSDOS) && !defined(__WIN__) && !defined(HAVE_BROKEN_NETINET_INCLUDES) && !defined(__BEOS__)
#include <netinet/ip.h>
#if !defined(alpha_linux_port)
#include <netinet/tcp.h>
#endif
#endif
#if defined(__EMX__) || defined(OS2)
#define ioctlsocket ioctl
#endif /* defined(__EMX__) */
#if defined(MSDOS) || defined(__WIN__)
#define O_NONBLOCK 1 /* For emulation of fcntl() */
#endif
#ifndef EWOULDBLOCK
#define SOCKET_EWOULDBLOCK SOCKET_EAGAIN
#endif
#ifndef __WIN__
#define HANDLE void *
......@@ -243,7 +217,8 @@ my_bool
vio_should_retry(Vio * vio __attribute__((unused)))
{
int en = socket_errno;
return en == SOCKET_EAGAIN || en == SOCKET_EINTR || en == SOCKET_EWOULDBLOCK;
return (en == SOCKET_EAGAIN || en == SOCKET_EINTR ||
en == SOCKET_EWOULDBLOCK);
}
......
......@@ -34,31 +34,6 @@
#include <my_sys.h>
#include <my_net.h>
#include <m_string.h>
#ifdef HAVE_POLL
#include <sys/poll.h>
#endif
#ifdef HAVE_SYS_IOCTL_H
#include <sys/ioctl.h>
#endif
#if defined(__EMX__)
#define ioctlsocket ioctl
#endif /* defined(__EMX__) */
#if defined(MSDOS) || defined(__WIN__)
#ifdef __WIN__
#undef errno
#undef EINTR
#undef EAGAIN
#define errno WSAGetLastError()
#define EINTR WSAEINTR
#define EAGAIN WSAEINPROGRESS
#endif /* __WIN__ */
#define O_NONBLOCK 1 /* For emulation of fcntl() */
#endif
#ifndef EWOULDBLOCK
#define EWOULDBLOCK EAGAIN
#endif
#ifndef __WIN__
#define HANDLE void *
......@@ -83,7 +58,7 @@ report_errors()
if (!any_ssl_error) {
DBUG_PRINT("info", ("No OpenSSL errors."));
}
DBUG_PRINT("info", ("BTW, errno=%d", errno));
DBUG_PRINT("info", ("BTW, errno=%d", scoket_errno));
DBUG_VOID_RETURN;
}
......@@ -102,7 +77,7 @@ void vio_ssl_delete(Vio * vio)
int vio_ssl_errno(Vio *vio __attribute__((unused)))
{
return errno; /* On Win32 this mapped to WSAGetLastError() */
return socket_errno; /* On Win32 this mapped to WSAGetLastError() */
}
......@@ -195,8 +170,9 @@ int vio_ssl_keepalive(Vio* vio, my_bool set_keep_alive)
my_bool
vio_ssl_should_retry(Vio * vio __attribute__((unused)))
{
int en = errno;
return en == EAGAIN || en == EINTR || en == EWOULDBLOCK;
int en = socket_errno;
return (en == SOCKET_EAGAIN || en == SOCKET_EINTR ||
en == SOCKET_EWOULDBLOCK);
}
......@@ -217,7 +193,7 @@ int vio_ssl_close(Vio * vio)
r= -1;
if (r)
{
DBUG_PRINT("error", ("close() failed, error: %d",errno));
DBUG_PRINT("error", ("close() failed, error: %d",socket_errno));
report_errors();
/* FIXME: error handling (not critical for MySQL) */
}
......@@ -257,7 +233,7 @@ my_bool vio_ssl_peer_addr(Vio * vio, char *buf)
if (getpeername(vio->sd, (struct sockaddr *) (& (vio->remote)),
&addrLen) != 0)
{
DBUG_PRINT("exit", ("getpeername, error: %d", errno));
DBUG_PRINT("exit", ("getpeername, error: %d", socket_errno));
DBUG_RETURN(1);
}
/* FIXME */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment