~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/drizzle_protocol/drizzle_protocol.cc

merge trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
26
26
#include "drizzled/internal/my_sys.h"
27
27
#include "drizzled/internal/m_string.h"
28
28
#include <algorithm>
29
 
 
 
29
#include <iostream>
 
30
#include <boost/program_options.hpp>
 
31
#include <drizzled/module/option_map.h>
30
32
#include "pack.h"
31
33
#include "errmsg.h"
32
34
#include "drizzle_protocol.h"
38
40
{
39
41
extern uint32_t global_thread_id;
40
42
}
41
 
 
 
43
namespace po= boost::program_options;
42
44
using namespace drizzled;
43
45
using namespace std;
44
46
 
663
665
    server_capabilites|= CLIENT_COMPRESS;
664
666
#endif /* HAVE_COMPRESS */
665
667
 
666
 
    end= buff + strlen(VERSION);
 
668
    end= buff + strlen(PANDORA_RELEASE_VERSION);
667
669
    if ((end - buff) >= SERVER_VERSION_LENGTH)
668
670
      end= buff + (SERVER_VERSION_LENGTH - 1);
669
 
    memcpy(buff, VERSION, end - buff);
 
671
    memcpy(buff, PANDORA_RELEASE_VERSION, end - buff);
670
672
    *end= 0;
671
673
    end++;
672
674
 
812
814
  drizzleclient_net_write(&net, buff, 5);
813
815
}
814
816
 
815
 
static ListenDrizzleProtocol *listen_obj= NULL;
816
 
 
817
 
static int init(plugin::Context &context)
 
817
static int init(module::Context &context)
818
818
{
819
 
  listen_obj= new ListenDrizzleProtocol("drizzle_protocol", false);
820
 
  context.add(listen_obj); 
 
819
  const module::option_map &vm= context.getOptions();
 
820
  if (vm.count("port"))
 
821
  { 
 
822
    if (port > 65535)
 
823
    {
 
824
      errmsg_printf(ERRMSG_LVL_ERROR, _("Invalid value of port\n"));
 
825
      exit(-1);
 
826
    }
 
827
  }
 
828
 
 
829
  if (vm.count("connect-timeout"))
 
830
  {
 
831
    if (connect_timeout < 1 || connect_timeout > 300)
 
832
    {
 
833
      errmsg_printf(ERRMSG_LVL_ERROR, _("Invalid value for connect_timeout\n"));
 
834
      exit(-1);
 
835
    }
 
836
  }
 
837
 
 
838
  if (vm.count("read-timeout"))
 
839
  {
 
840
    if (read_timeout < 1 || read_timeout > 300)
 
841
    {
 
842
      errmsg_printf(ERRMSG_LVL_ERROR, _("Invalid value for read_timeout\n"));
 
843
      exit(-1);
 
844
    }
 
845
  }
 
846
 
 
847
  if (vm.count("write-timeout"))
 
848
  {
 
849
    if (write_timeout < 1 || write_timeout > 300)
 
850
    {
 
851
      errmsg_printf(ERRMSG_LVL_ERROR, _("Invalid value for write_timeout\n"));
 
852
      exit(-1);
 
853
    }
 
854
  }
 
855
 
 
856
  if (vm.count("retry-count"))
 
857
  {
 
858
    if (retry_count < 1 || retry_count > 100)
 
859
    {
 
860
      errmsg_printf(ERRMSG_LVL_ERROR, _("Invalid value for retry_count\n"));
 
861
      exit(-1);
 
862
    }
 
863
  }
 
864
 
 
865
  if (vm.count("buffer-length"))
 
866
  {
 
867
    if (buffer_length < 1024 || buffer_length > 1024*1024)
 
868
    {
 
869
      errmsg_printf(ERRMSG_LVL_ERROR, _("Invalid value for buffer_length\n"));
 
870
      exit(-1);
 
871
    }
 
872
  }
 
873
 
 
874
  if (vm.count("bind-address"))
 
875
  {
 
876
    bind_address= strdup(vm["bind-address"].as<string>().c_str());
 
877
  }
 
878
 
 
879
  else
 
880
  {
 
881
    bind_address= NULL;
 
882
  }
 
883
  
 
884
  context.add(new ListenDrizzleProtocol("drizzle_protocol", false)); 
821
885
  return 0;
822
886
}
823
887
 
842
906
static DRIZZLE_SYSVAR_STR(bind_address, bind_address, PLUGIN_VAR_READONLY,
843
907
                          N_("Address to bind to."), NULL, NULL, NULL);
844
908
 
 
909
static void init_options(drizzled::module::option_context &context)
 
910
{
 
911
  context("port",
 
912
          po::value<uint32_t>(&port)->default_value(0),
 
913
          N_("Port number to use for connection or 0 for "
 
914
                              "default to, in order of "
 
915
                              "preference, drizzle.cnf, $DRIZZLE_TCP_PORT, "
 
916
                              "built-in default (4427)."));
 
917
  context("connect-timeout",
 
918
          po::value<uint32_t>(&connect_timeout)->default_value(10),
 
919
          N_("Connect Timeout."));
 
920
  context("read-timeout",
 
921
          po::value<uint32_t>(&read_timeout)->default_value(30),
 
922
          N_("Read Timeout."));
 
923
  context("write-timeout",
 
924
          po::value<uint32_t>(&write_timeout)->default_value(60),
 
925
          N_("Write Timeout."));
 
926
  context("retry-count",
 
927
          po::value<uint32_t>(&retry_count)->default_value(10),
 
928
          N_("Retry Count."));
 
929
  context("buffer-length",
 
930
          po::value<uint32_t>(&buffer_length)->default_value(16384),
 
931
          N_("Buffer length."));
 
932
  context("bind-address",
 
933
          po::value<string>(),
 
934
          N_("Address to bind to."));
 
935
}
 
936
 
845
937
static drizzle_sys_var* sys_variables[]= {
846
938
  DRIZZLE_SYSVAR(port),
847
939
  DRIZZLE_SYSVAR(connect_timeout),
855
947
 
856
948
} /* namespace drizzle_protocol */
857
949
 
858
 
DRIZZLE_PLUGIN(drizzle_protocol::init, drizzle_protocol::sys_variables);
 
950
DRIZZLE_PLUGIN(drizzle_protocol::init, drizzle_protocol::sys_variables, drizzle_protocol::init_options);