From 76164b89d13331a01d5e5d03b09d3ecaf1a405c3 Mon Sep 17 00:00:00 2001 From: unknown Date: Sat, 9 Apr 2005 14:28:39 +0400 Subject: WL#2246 "IM: Add ability to change instance options, add server logs handling" ported to the current version of the IM server-tools/instance-manager/commands.cc: Log and set options commands added server-tools/instance-manager/commands.h: Log and set options commands added server-tools/instance-manager/factory.cc: Log and set options factory entries added server-tools/instance-manager/factory.h: prototypes added server-tools/instance-manager/instance_options.cc: fill_log_options() added server-tools/instance-manager/instance_options.h: log processing options and funcctions added server-tools/instance-manager/messages.cc: new error messages added (log and option processing-related) server-tools/instance-manager/mysql_connection.cc: minor fixes server-tools/instance-manager/mysql_manager_error.h: new error codes added server-tools/instance-manager/parse.cc: parser fixed to recognize new commands. function to parse command-line options added server-tools/instance-manager/parse.h: header fixed in line with .cc changes server-tools/instance-manager/parse_output.cc: cleanup server-tools/instance-manager/parse_output.h: header guards added server-tools/instance-manager/protocol.cc: Protocol support extended to provide messages in ok packet server-tools/instance-manager/protocol.h: protocol support extended: ok packet could contain messages --- server-tools/instance-manager/protocol.cc | 53 +++++++++++++++++++++++-------- 1 file changed, 40 insertions(+), 13 deletions(-) (limited to 'server-tools/instance-manager/protocol.cc') diff --git a/server-tools/instance-manager/protocol.cc b/server-tools/instance-manager/protocol.cc index 9c8975a78be..f0928743716 100644 --- a/server-tools/instance-manager/protocol.cc +++ b/server-tools/instance-manager/protocol.cc @@ -24,15 +24,25 @@ static char eof_buff[1]= { (char) 254 }; /* Marker for end of fields */ -int net_send_ok(struct st_net *net, unsigned long connection_id) + +int net_send_ok(struct st_net *net, unsigned long connection_id, + const char *message) { - char buff[1 + // packet type code - 9 + // affected rows count - 9 + // connection id - 2 + // thread return status - 2]; // warning count + /* + The format of a packet + 1 packet type code + 1-9 affected rows count + 1-9 connection id + 2 thread return status + 2 warning count + 1-9 + message length message to send (isn't stored if no message) + */ + Buffer buff; + char *pos= buff.buffer; + + /* check that we have space to hold mandatory fields */ + buff.reserve(0, 23); - char *pos= buff; enum { OK_PACKET_CODE= 0 }; *pos++= OK_PACKET_CODE; pos= net_store_length(pos, (ulonglong) 0); @@ -43,7 +53,15 @@ int net_send_ok(struct st_net *net, unsigned long connection_id) int2store(pos, 0); pos+= 2; - return my_net_write(net, buff, pos - buff) || net_flush(net); + uint position= pos - buff.buffer; /* we might need it for message */ + + if (message != NULL) + { + buff.reserve(position, 9 + strlen(message)); + store_to_string(&buff, message, &position); + } + + return my_net_write(net, buff.buffer, position) || net_flush(net); } @@ -99,15 +117,15 @@ char *net_store_length(char *pkg, uint length) } -int store_to_string(Buffer *buf, const char *string, uint *position) +int store_to_string(Buffer *buf, const char *string, uint *position, + uint string_len) { uint currpos; - uint string_len; - string_len= strlen(string); - if (buf->reserve(*position, 2)) + if (buf->reserve(*position, 9)) goto err; - currpos= (net_store_length(buf->buffer + *position, string_len) - buf->buffer); + currpos= (net_store_length(buf->buffer + *position, + (ulonglong) string_len) - buf->buffer); if (buf->append(currpos, string, string_len)) goto err; *position= *position + string_len + (currpos - *position); @@ -118,6 +136,15 @@ err: } +int store_to_string(Buffer *buf, const char *string, uint *position) +{ + uint string_len; + + string_len= strlen(string); + return store_to_string(buf, string, position, string_len); +} + + int send_eof(struct st_net *net) { char buff[1 + /* eof packet code */ -- cgit v1.2.1