Commit 311e99d7 authored by unknown's avatar unknown

Libmysqld improvements

libmysqld/lib_sql.cc:
  select::send rewritten
  mysql_server_init trimmed
sql/convert.cc:
  Necessary additions to CONVERT
sql/item.cc:
  embedded_send functions added
sql/item.h:
  embedded_send functions added
sql/mysqld.cc:
  main() trimmed
sql/sql_class.h:
  CONVERT::convert_back added
parent cda34818
This diff is collapsed.
......@@ -473,3 +473,12 @@ bool CONVERT::store(String *packet,const char *from,uint length)
packet->length((uint) (to-packet->ptr()));
return 0;
}
#ifdef EMBEDDED_LIBRARY
void CONVERT::convert_back(char *dest, const char *source, uint length) const
{
for (char *end= dest+length; dest < end; dest++, source++)
*dest= to_map[*source];
}
#endif
......@@ -816,11 +816,64 @@ bool Item::send(THD *thd, String *packet)
return net_store_data(packet,res->ptr(),res->length());
}
bool Item_null::send(THD *thd, String *packet)
{
return net_store_null(packet);
}
#ifdef EMBEDDED_LIBRARY
bool Item::embedded_send(const CONVERT *convert, CHARSET_INFO *charset, MEM_ROOT *alloc,
char **result, ulong *length)
{
char buff[MAX_FIELD_WIDTH];
String s(buff, sizeof(buff), charset), *value;
if (!(value=val_str(&s)) ||
!(*result=alloc_root(alloc, value->length() + 1)))
return true;
*length= value->length();
if (convert)
convert->convert_back(*result, value->ptr(), *length);
else
memcpy(*result, value->ptr(), *length);
(*result)[*length]= 0;
return false;
}
bool Item_null::embedded_send(const CONVERT *convert, CHARSET_INFO *charset, MEM_ROOT *alloc,
char **result, ulong *length)
{
*result= NULL;
return false;
}
bool Item_field::embedded_send(const CONVERT *convert, CHARSET_INFO *charset, MEM_ROOT *alloc,
char **result, ulong *length)
{
if (result_field->is_null())
{
result= NULL;
return false;
}
char buff[MAX_FIELD_WIDTH];
String tmp(buff,sizeof(buff),default_charset_info);
result_field->val_str(&tmp,&tmp);
if (!(*result=alloc_root(alloc, tmp.length() + 1)))
return true;
*length= tmp.length();
if (convert)
convert->convert_back(*result, tmp.ptr(), *length);
else
memcpy(*result, tmp.ptr(), *length);
(*result)[*length]= 0;
return false;
}
#endif
/*
This is used for HAVING clause
Find field in select list having the same name
......
......@@ -22,6 +22,8 @@
struct st_table_list;
void item_init(void); /* Init item functions */
class CONVERT;
class Item {
Item(const Item &); /* Prevent use of these */
void operator=(Item &);
......@@ -59,6 +61,10 @@ class Item {
virtual int save_safe_in_field(Field *field)
{ return save_in_field(field); }
virtual bool send(THD *thd, String *str);
#ifdef EMBEDDED_LIBRARY
virtual bool embedded_send(const CONVERT *convert, CHARSET_INFO *charset, MEM_ROOT *alloc,
char **result, ulong *length);
#endif
virtual bool eq(const Item *, bool binary_cmp) const;
virtual Item_result result_type () const { return REAL_RESULT; }
virtual enum Type type() const =0;
......@@ -128,6 +134,10 @@ class Item_field :public Item_ident
{
return result_field->send(thd,str_arg);
}
#ifdef EMBEDDED_LIBRARY
bool embedded_send(const CONVERT *convert, CHARSET_INFO *charset, MEM_ROOT *alloc,
char **result, ulong *length);
#endif
void make_field(Send_field *field);
bool fix_fields(THD *, struct st_table_list *, Item **);
int save_in_field(Field *field);
......@@ -160,6 +170,10 @@ class Item_null :public Item
enum Item_result result_type () const
{ return STRING_RESULT; }
bool send(THD *thd, String *str);
#ifdef EMBEDDED_LIBRARY
bool embedded_send(const CONVERT *convert, CHARSET_INFO *charset, MEM_ROOT *alloc,
char **result, ulong *length);
#endif
bool basic_const_item() const { return 1; }
Item *new_item() { return new Item_null(name); }
bool is_null() { return 1; }
......@@ -423,6 +437,11 @@ class Item_ref :public Item_ident
return (null_value=(*ref)->get_date(ltime,fuzzydate));
}
bool send(THD *thd, String *tmp) { return (*ref)->send(thd, tmp); }
#ifdef EMBEDDED_LIBRARY
bool embedded_send(const CONVERT *convert, CHARSET_INFO *charset, MEM_ROOT *alloc,
char **result, ulong *length)
{ return (*ref)->embedded_send(convert, charset, alloc, result, length); }
#endif
void make_field(Send_field *field) { (*ref)->make_field(field); }
bool fix_fields(THD *, struct st_table_list *, Item **);
int save_in_field(Field *field) { return (*ref)->save_in_field(field); }
......
......@@ -1768,13 +1768,11 @@ bool open_log(MYSQL_LOG *log, const char *hostname,
no_auto_events);
}
static int init_common_variables(char *progname,
const char *conf_file_name, int argc, char **argv,
static int init_common_variables(const char *conf_file_name, int argc, char **argv,
const char **groups)
{
my_umask=0660; // Default umask for new files
my_umask_dir=0700; // Default umask for new directories
MY_INIT(progname); // init my_sys library & pthreads
umask(((~my_umask) & 0666));
tzset(); // Set tzname
......@@ -1999,7 +1997,74 @@ static void create_maintenance_thread()
}
}
#ifdef _DUMMY
static void create_shutdown_thread()
{
#ifdef __WIN__
{
hEventShutdown=CreateEvent(0, FALSE, FALSE, event_name);
pthread_t hThread;
if (pthread_create(&hThread,&connection_attrib,handle_shutdown,0))
sql_print_error("Warning: Can't create thread to handle shutdown requests");
// On "Stop Service" we have to do regular shutdown
Service.SetShutdownEvent(hEventShutdown);
}
#endif
#ifdef OS2
{
pthread_cond_init( &eventShutdown, NULL);
pthread_t hThread;
if (pthread_create(&hThread,&connection_attrib,handle_shutdown,0))
sql_print_error("Warning: Can't create thread to handle shutdown requests");
}
#endif
}
#ifdef __NT__
void create_named_pipe_thread()
{
if (hPipe == INVALID_HANDLE_VALUE &&
(!have_tcpip || opt_disable_networking))
{
sql_print_error("TCP/IP or --enable-named-pipe should be configured on NT OS");
unireg_abort(1);
}
else
{
pthread_mutex_lock(&LOCK_thread_count);
(void) pthread_cond_init(&COND_handler_count,NULL);
{
pthread_t hThread;
handler_count=0;
if (hPipe != INVALID_HANDLE_VALUE && opt_enable_named_pipe)
{
handler_count++;
if (pthread_create(&hThread,&connection_attrib,
handle_connections_namedpipes, 0))
{
sql_print_error("Warning: Can't create thread to handle named pipes");
handler_count--;
}
}
if (have_tcpip && !opt_disable_networking)
{
handler_count++;
if (pthread_create(&hThread,&connection_attrib,
handle_connections_sockets, 0))
{
sql_print_error("Warning: Can't create thread to handle named pipes");
handler_count--;
}
}
while (handler_count > 0)
pthread_cond_wait(&COND_handler_count,&LOCK_thread_count);
}
pthread_mutex_unlock(&LOCK_thread_count);
}
}
#endif
#ifdef __WIN__
int win_main(int argc, char **argv)
#else
......@@ -2009,25 +2074,18 @@ int main(int argc, char **argv)
int init_error;
DEBUGGER_OFF;
// MAIN_THD;
/*
Initialize signal_th and shutdown_th to main_th for default value
as we need to initialize them to something safe. They are used
when compiled with safemalloc.
*/
// SIGNAL_THD;
// SHUTDOWN_THD;
/*#ifdef _CUSTOMSTARTUPCONFIG_
#ifdef _CUSTOMSTARTUPCONFIG_
if (_cust_check_startup())
{
/ * _cust_check_startup will report startup failure error * /
exit( 1 );
}
#endif
*/
if ((init_error=init_common_variables(argv[0], MYSQL_CONFIG_NAME,
argc, argv, load_default_groups)))
MY_INIT(argv[0]); // init my_sys library & pthreads
if ((init_error=init_common_variables(MYSQL_CONFIG_NAME,
argc, argv, load_default_groups)))
if (init_error == 2)
unireg_abort(1);
else
......@@ -2145,70 +2203,14 @@ The server will not act as a slave.");
}
}
#ifdef __WIN__
{
hEventShutdown=CreateEvent(0, FALSE, FALSE, event_name);
pthread_t hThread;
if (pthread_create(&hThread,&connection_attrib,handle_shutdown,0))
sql_print_error("Warning: Can't create thread to handle shutdown requests");
// On "Stop Service" we have to do regular shutdown
Service.SetShutdownEvent(hEventShutdown);
}
#endif
#ifdef OS2
{
pthread_cond_init( &eventShutdown, NULL);
pthread_t hThread;
if (pthread_create(&hThread,&connection_attrib,handle_shutdown,0))
sql_print_error("Warning: Can't create thread to handle shutdown requests");
}
#endif
create_shutdown_thread();
create_maintenance_thread();
printf(ER(ER_READY),my_progname,server_version,"");
fflush(stdout);
#ifdef __NT__
if (hPipe == INVALID_HANDLE_VALUE &&
(!have_tcpip || opt_disable_networking))
{
sql_print_error("TCP/IP or --enable-named-pipe should be configured on NT OS");
unireg_abort(1);
}
else
{
pthread_mutex_lock(&LOCK_thread_count);
(void) pthread_cond_init(&COND_handler_count,NULL);
{
pthread_t hThread;
handler_count=0;
if (hPipe != INVALID_HANDLE_VALUE && opt_enable_named_pipe)
{
handler_count++;
if (pthread_create(&hThread,&connection_attrib,
handle_connections_namedpipes, 0))
{
sql_print_error("Warning: Can't create thread to handle named pipes");
handler_count--;
}
}
if (have_tcpip && !opt_disable_networking)
{
handler_count++;
if (pthread_create(&hThread,&connection_attrib,
handle_connections_sockets, 0))
{
sql_print_error("Warning: Can't create thread to handle named pipes");
handler_count--;
}
}
while (handler_count > 0)
pthread_cond_wait(&COND_handler_count,&LOCK_thread_count);
}
pthread_mutex_unlock(&LOCK_thread_count);
}
create_named_pipe_thread();
#else
handle_connections_sockets(0);
#ifdef EXTRA_DEBUG2
......@@ -2254,7 +2256,8 @@ The server will not act as a slave.");
exit(0);
return(0); /* purecov: deadcode */
}
#endif
#ifdef _DUMMY
#ifdef __WIN__
int win_main(int argc, char **argv)
......@@ -2693,6 +2696,7 @@ The server will not act as a slave.");
exit(0);
return(0); /* purecov: deadcode */
}
#endif
/****************************************************************************
Main and thread entry function for Win32
......
......@@ -178,6 +178,9 @@ class CONVERT
convert_array(from_map, (uchar*) a,length);
}
bool store(String *, const char *,uint);
#ifdef EMBEDDED_LIBRARY
void convert_back(char *dest, const char *source, uint length) const;
#endif
inline uint number() { return numb; }
};
......
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