Exemplo n.º 1
0
void Database::addInitialHandles( uint desired )
{
    Endpoint srv( Configuration::DbAddress, Configuration::DbPort );

    if ( desired == 0 ) {
        uint max = Configuration::scalar( Configuration::DbMaxHandles );
        desired = 3;
        if ( Configuration::toggle( Configuration::Security ) &&
             srv.protocol() == Endpoint::Unix )
            desired = max;
        if ( desired > max )
            desired = max;
    }

    while ( desired ) {
        newHandle();
        desired--;
    }
}
Exemplo n.º 2
0
TEST(ServerImpl_onRequest, PiggybackedResponseForDELETE) {
  // GIVEN a Server with a response handler
  auto conn = std::make_shared<ConnectionMock>();
  CoAP::Messaging srv(conn);
  srv.requestHandler()
      .onUri("/")
      .onDelete([](const Path& path){
        return CoAP::RestResponse().withCode(CoAP::Code::Deleted);
      });

  // WHEN it receives a confirmable message with a GET request
  auto msg = CoAP::Message(CoAP::Type::Confirmable, 0, CoAP::Code::DELETE, 0, "/");
  srv.onMessage(msg, 0, 0);

  // THEN it sends an ACK message with a piggybacked response
  ASSERT_EQ(1, conn->sentMessages_.size());
  EXPECT_EQ(CoAP::Type::Confirmable, conn->sentMessages_[0].type());
  EXPECT_EQ(CoAP::Code::Deleted, conn->sentMessages_[0].code());
}
Exemplo n.º 3
0
//    Client            Server
//      |       NON       |   NonConfirmable request
//      |---------------->|
//      |                 |
//      |       NON       |   NonConfirmable answer for request
//      |<----------------|
TEST(ServerImpl_onMessage, NoAcknowledgeForNonConfirmableMessage) {
  // GIVEN a NonConfirmable message
  auto conn = std::make_shared<ConnectionMock>();
  CoAP::Messaging srv(conn);
  srv.requestHandler()
      .onUri("/")
          .onGet([](const Path& path){
            return CoAP::RestResponse().withCode(CoAP::Code::Content);
          });
  auto msg = CoAP::Message(CoAP::Type::NonConfirmable, 0, CoAP::Code::GET, 0, "/");

  // WHEN the NonConfirmable message is sent to the server
  srv.onMessage(msg, 0, 0);

  // THEN we only get the answer back, but no acknowledge for reception of the message
  ASSERT_EQ(1, conn->sentMessages_.size());
  EXPECT_EQ(CoAP::Type::NonConfirmable, conn->sentMessages_[0].type());
  EXPECT_EQ(CoAP::Code::Content, conn->sentMessages_[0].responseCode());
}
UnexpandedRoute* 
ParserRouteHandler::redoUnexpandedRoute(const RouteID& oldRouteID,
                                        const RouteRequestParams& rrParams,
                                        const RequestUserData& user,
                                        const TopRegionRequest* topReq,
                                        const DisturbanceList* disturbances)
{
   auto_ptr<RouteRequest> rr( redoRoute( oldRouteID, rrParams, user, 
                                         topReq, disturbances ) );
   UnexpandedRoute* ur = NULL;
   if ( rr.get() != NULL ) {
      const RouteReplyPacket* redoneRouteReply = rr->getRouteReplyPacket();
      const DriverPref& prefs = rrParams.getDriverPrefs();
      auto_ptr<SubRouteVector> srv( redoneRouteReply->createSubRouteVector( &prefs ) );
      ur = new UnexpandedRoute( *srv, prefs);
      delete rr->getAnswer();
   }
   return ur;
}
Exemplo n.º 5
0
//    Client            Server
//      |       CON       |   Confirmable request
//      |---------------->|
//      |                 |
//      |       ACK       |   Acknowledge for reception of request
//      |<----------------|
//      |                 |
//      |       CON       |   Confirmable answer for request
//      |<----------------|
//      :                 :
//      :       ACK       :   Client acknowledge is not tested here
//      :- - - - - - - - >:
TEST(ServerImpl_onMessage, AcknowledgeForConfirmableMessage) {
  // GIVEN
  auto conn = std::make_shared<ConnectionMock>();
  CoAP::Messaging srv(conn);
  srv.requestHandler()
      .onUri("/")
          .onGet([](const Path& path){
            return CoAP::RestResponse().withCode(CoAP::Code::Content);
          }, true);
  auto msg = CoAP::Message(CoAP::Type::Confirmable, 0, CoAP::Code::GET, 0, "/");

  // WHEN
  srv.onMessage(msg, 0, 0);

  // THEN
  ASSERT_EQ(2, conn->sentMessages_.size());
  EXPECT_EQ(CoAP::Type::Acknowledgement, conn->sentMessages_[0].type());
  EXPECT_EQ(CoAP::Type::Confirmable, conn->sentMessages_[1].type());
  EXPECT_EQ(CoAP::Code::Content, conn->sentMessages_[1].code());
}
Exemplo n.º 6
0
void
json_introspection_server_t::dispatch (svccb *sbp)
{
  if (!sbp) { 
    delete this;
  } else {
    switch (sbp->proc ()) {
    case JSON_INTROSPECTION_FETCH_CONSTANTS:
      {
	rpc::json_introspection_prog_1::
	  json_introspection_fetch_constants_srv_t<svccb> srv (sbp);
	srv.reply (constant_set ());
      }
      break;
    default:
      sbp->reject (PROC_UNAVAIL);
      break;
    }
  }
}
Exemplo n.º 7
0
int main(int argc,char **argv)
{
	try {
		cppcms::service srv(argc,argv);
		booster::intrusive_ptr<cppcms::application> async = new async_unit_test(srv);
		srv.applications_pool().mount( async, cppcms::mount_point("/async") );
		srv.applications_pool().mount( cppcms::applications_factory<unit_test>(), cppcms::mount_point("/sync"));
		srv.after_fork(submitter(srv));
		srv.run();
	}
	catch(std::exception const &e) {
		std::cerr << e.what() << std::endl;
		return EXIT_FAILURE;
	}
	if(bad_count != 3 || calls != 4) {
		std::cerr << "Failed bad_count = " << bad_count << " calls = " << calls << std::endl;
		return EXIT_FAILURE;
	}
	return EXIT_SUCCESS;
}
Exemplo n.º 8
0
int
main(int argc, char **argv)
{
    int r;
    Srv s = {};
    s.wal.filesz = Filesizedef;
    struct job list = {};

    progname = argv[0];
    opts(argc, argv, &s.wal);

    if (verbose) {
        printf("pid %d\n", getpid());
    }

    r = make_server_socket(host_addr, port);
    if (r == -1) twarnx("make_server_socket()"), exit(111);
    s.sock.fd = r;

    prot_init();

    if (user) su(user);
    set_sig_handlers();

    if (s.wal.use) {
        // We want to make sure that only one beanstalkd tries
        // to use the wal directory at a time. So acquire a lock
        // now and never release it.
        if (!waldirlock(&s.wal)) {
            twarnx("failed to lock wal dir %s", s.wal.dir);
            exit(10);
        }

        list.prev = list.next = &list;
        walinit(&s.wal, &list);
        prot_replay(&s, &list);
    }

    srv(&s);
    return 0;
}
Exemplo n.º 9
0
TEST(ServerImpl_onRequest, DelegatesPostRequestAndReceivesResponse) {
  // GIVEN
  auto conn = std::make_shared<ConnectionMock>();
  CoAP::Messaging srv(conn);
  auto postCalled = 0;
  srv.requestHandler()
      .onUri("/*")
          .onPost([&postCalled](const Path& path, std::string payload){
            ++postCalled;
            return CoAP::RestResponse().withCode(CoAP::Code::Created);
          });
  auto msg = CoAP::Message(CoAP::Type::NonConfirmable, 0, CoAP::Code::POST, 0, "/some/where");

  // WHEN NonConfirmable message with POST request is sent to the Server
  auto reply = srv.getServer().onRequest(msg, 0, 0);

  // THEN RequestHandler POST is called with the message and an reply is sent
  EXPECT_EQ(1, postCalled);

  EXPECT_EQ(CoAP::Code::Created, reply.code());
}
Exemplo n.º 10
0
int main(int argc, char **argv) {
    std::string address("amqp://127.0.0.1:5672/examples");
    options opts(argc, argv);

    opts.add_value(address, 'a', "address", "listen on URL", "URL");

    try {
        opts.parse();

        server srv(address);
        proton::container(srv).run();

        return 0;
    } catch (const bad_option& e) {
        std::cout << opts << std::endl << e.what() << std::endl;
    } catch (const std::exception& e) {
        std::cerr << e.what() << std::endl;
    }

    return 1;
}
Exemplo n.º 11
0
int main(int argc, char ** argv) {
    if (argc < 2) {
        printf("Usage: %s <port number>", argv[0]);
        return 1;
    }
    
    try {
        if (argc < 3 || strcmp("--no-daemon", argv[2]) != 0) {
            daemonize();
        }
        
        signal(SIGPIPE, SIG_IGN);
        signal(SIGCHLD, SIG_IGN);

        server srv((uint16_t) atoi(argv[1]));
        srv.run();
    } catch (const errno_exception& ex) {
        fprintf(stderr, "%s: %s", ex.description.data(), strerror(ex.err));
    }
    return 0;
}
Exemplo n.º 12
0
TEST(ServerImpl_onRequest, DelegatesDeleteRequestAndReceivesResponse) {
  // GIVEN
  auto conn = std::make_shared<ConnectionMock>();
  CoAP::Messaging srv(conn);
  auto deleteCalled = 0;
  srv.requestHandler()
      .onUri("/*")
        .onDelete([&deleteCalled](const Path& path){
          ++deleteCalled;
          return CoAP::RestResponse().withCode(CoAP::Code::Deleted);
        });
  auto msg = CoAP::Message(CoAP::Type::NonConfirmable, 0, CoAP::Code::DELETE, 0, "/some/where");

  // WHEN NonConfirmable message with DELETE request is sent to the Server
  auto reply = srv.getServer().onRequest(msg, 0, 0);

  // THEN RequestHandler DELETE is called with the message and an reply is sent
  EXPECT_EQ(1, deleteCalled);

  EXPECT_EQ(CoAP::Code::Deleted, reply.code());
}
Exemplo n.º 13
0
void
main(int argc, char **argv)
{
	int i;

	ARGBEGIN{
	case 'D':
		dbg++;
		break;
	case 'c':
		chatty9p++;
		break;
	default:
		fprint(2, "Usage: grepfs /path/to/files/*\n");
		exits("usage");
		break;
	}ARGEND

	if(argc < 1){
		fprint(2, "Usage: grepfs /path/to/files/*\n");
		exits("usage");
	}
	grepargs = emalloc9p(sizeof(*grepargs) * (argc + 4));
	*grepargs = "grep";
	for(i = 0; i < argc; i++)
		grepargs[i+3] = argv[i];
	grepargs[i+3] = nil;
	grepflags = estrdup9p("-n");
	starttime = grepatime = grepmtime = time(nil);
	if(dbg){
		logfd = create("/tmp/grepfs.log", OWRITE, 0644);
		postmountsrv(&fs, "grepfs", nil, 0);
	}else{
		fs.infd = 0;
		fs.outfd = 1;
		srv(&fs);
	}
	exits(0);
}
Exemplo n.º 14
0
    virtual void *Entry()
    {
        wxSocketServer srv(LocalAddress(m_port), wxSOCKET_REUSEADDR);
        CPPUNIT_ASSERT( srv.IsOk() );

        // FIXME: this is still not atomic, of course and the main thread could
        //        call Connect() before we have time to Accept() but there is
        //        no way to fix it with current API
        {
            wxMutexLocker lock(gs_mutex);
            gs_cond.Signal();
        }

        wxSocketBase *socket = srv.Accept();
        if ( socket )
        {
            (*m_accept)(*socket);
            delete socket;
        }

        return NULL;
    }
Exemplo n.º 15
0
void
tst2_srv_t::mget (ptr<amt::req_t> b)
{
  rpc::tst2_prog_1::tst2_mget_srv_t<amt::req_t> srv (b);
  const tst2_mget_arg_t *arg = srv.getarg ();
  ptr<tst2_mget_res_t> res = srv.alloc_res (ADB_OK);

  if (!_q_mget->execute (arg->sleep_msec, arg->lim)) {
    res->set_status (ADB_EXECUTE_ERROR);
    TWARN("mget error: " << _q_mget->error ());
  } else {
    adb_status_t s;
    tst2_data_t dat;
    while ((s = _q_mget->fetch (&dat.d, &dat.i, &dat.pk, &dat.d2)) == ADB_OK) {
      res->rows->push_back (dat);
    }
    if (s != ADB_NOT_FOUND) {
      TWARN("mget error: " << _q_mget->error ());
      res->set_status (s);
    }
  }
  srv.reply (res);
}
Exemplo n.º 16
0
int main()
{
	try {
		cppcms::json::value cfg;
		cfg["cache"]["backend"]="thread_shared";
		cfg["cache"]["limit"]=100;
		cppcms::service srv(cfg);
		test_app app(srv);

		app.set_context();

		app.test_basic();
		app.test_gzip();
		app.test_objects();
		test_independent(srv);
	}
	catch(std::exception const &e)
	{
		std::cerr << "Fail " << e.what() << std::endl;
		return 1;
	}
	std::cout << "Ok" << std::endl;
	return 0;
}
Exemplo n.º 17
0
int main(int argc, char* argv[])
{
  try
  {
    cxxtools::Arg<std::string> ip(argc, argv, 'i');
    cxxtools::Arg<unsigned short> port(argc, argv, 'p', 7010);

    // Instantiate a listener socket
    cxxtools::net::TcpServer srv(ip, port);

    // Instantiate a network iostream and accept a incoming connection.
    // This will block until a connection arrives.
    cxxtools::net::TcpStream out(srv);

    // We write 2 messages using xmlary serialization to the socket.
    out << cxxtools::xml::Xml(Msg(42, "Hi"), "root")
        << cxxtools::xml::Xml(Msg(43, "There"), "root")
        << std::flush;
  }
  catch (const std::exception& e)
  {
    std::cerr << e.what() << std::endl;
  }
}
/**
 * This tutorial demonstrates simple sending of messages over the ROS system.
 */
int main(int argc, char **argv)
{
	/**
	* The ros::init() function needs to see argc and argv so that it can perform
	* any ROS arguments and name remapping that were provided at the command line. For programmatic
	* remappings you can use a different version of init() which takes remappings
	* directly, but for most command-line programs, passing argc and argv is the easiest
	* way to do it.  The third argument to init() is the name of the node.
	*
	* You must call one of the versions of ros::init() before using any other
	* part of the ROS system.
	*/
	ros::init(argc, argv, "grasp_service_server");

	/**
	* NodeHandle is the main access point to communications with the ROS system.
	* The first NodeHandle constructed will fully initialize this node, and the last
	* NodeHandle destructed will close down the node.
	*/
	ros::NodeHandle n;

	// create an instance of the exemplary service server class
	HermesGraspServiceServer srv(n);

	// initialize the service server (for details see comments in class)
	srv.init();

	/**
	* ros::spin() will enter a loop, pumping callbacks.  With this version, all
	* callbacks will be called from within this thread (the main one).  ros::spin()
	* will exit when Ctrl-C is pressed, or the node is shutdown by the master.
	*/
	ros::spin();

	return 0;
}
Exemplo n.º 19
0
int main(int argc, char** argv)
{
	// get a configuration object
	Configuration &conf = Configuration::getInstance();

	int opt = 0;
	std::string p_hostname = conf.getHostname();
	std::string p_iface = "lo";
	std::string p_ntpserver = "127.0.0.1";
	bool p_gps = false;
	unsigned int _p_disco_port = 3232;
	unsigned int _p_port = 3486;

	while((opt = ::getopt(argc, argv, "hd:vgp:n:i:t:")) != -1)
	{
		switch (opt)
		{
		case 'h':
			print_help();
			return 0;

		case 'd':
			_p_disco_port = ::atoi(optarg);
			break;

		case 'p':
			_p_port = atoi(optarg);
			break;

		case 'g':
			p_gps = true;
			break;

		case 'n':
			p_hostname = optarg;
			break;

		case 'i':
			p_iface = optarg;
			break;

		case 't':
			p_ntpserver = optarg;
			break;

		default:
			std::cout << "unknown command" << std::endl;
			return -1;
		}
	}

	// some output for the user
	std::cout << "startup of hydra node daemon" << std::endl;
	std::cout << "hostname: " << p_hostname << std::endl;

	// listen on interface
	const ibrcommon::vinterface iface(p_iface);
	conf.setInterface(iface);

	// create a fake gps
	FakeGPS &gps = FakeGPS::getInstance();
	if (!p_gps) gps.disable();

	// create clock monitor instance
	ClockMonitor &cm = ClockMonitor::getInstance();
	cm.setReference(p_ntpserver);
	cm.start();

	// listen on incoming tcp connections
	CommandServer srv(_p_port);
	srv.start();

	while (true)
	{
		try {
			// run discovery module
			DiscoverComponent disco(p_hostname, _p_disco_port, iface);
			disco.run();
		} catch (const std::exception&) {
			// error retry in 2 seconds
			std::cout << "can not listen on multicast socket" << std::endl;
			ibrcommon::Thread::sleep(2000);
		}
	}
}
Exemplo n.º 20
0
 void texture::to_ps(ID3D11DeviceContext* context, UINT slot)
 {
     ID3D11ShaderResourceView* v[] = { srv() };
     context->PSSetShaderResources(slot, 1, v);
 }
Exemplo n.º 21
0
int main(int argc, char ** argv) {
  int iline=0, i, iarg=1, nfields=1, jmax=0, writetxt=0, writemat=0, grpsize=1;
  int membuf=1048576;
  char * here, *linebuf, *readbuf;
  string ifname = "", ofname = "", mfname = "", ffname = "", matfname = "", fdelim="\t", suffix="";
  if (argc < 2) {
    printf("%s", usage);
    return 1;
  }
  while (iarg < argc) {
    if (strncmp(argv[iarg], "-d", 2) == 0) {
      fdelim = argv[++iarg];
    } else if (strncmp(argv[iarg], "-c", 2) == 0) {
      suffix=".gz";
    } else if (strncmp(argv[iarg], "-f", 2) == 0) {
      ffname = argv[++iarg];
    } else if (strncmp(argv[iarg], "-i", 2) == 0) {
      ifname = argv[++iarg];
    } else if (strncmp(argv[iarg], "-m", 2) == 0) {
      mfname = argv[++iarg];
    } else if (strncmp(argv[iarg], "-o", 2) == 0) {
      ofname = argv[++iarg];
    } else if (strncmp(argv[iarg], "-s", 2) == 0) {
      membuf = strtol(argv[++iarg],NULL,10);
    } else if (strncmp(argv[iarg], "-?", 2) == 0) {
      printf("%s", usage);
      return 1;
    } else if (strncmp(argv[iarg], "-h", 2) == 0) {
      printf("%s", usage);
      return 1;
    } else {
      cout << "Unknown option " << argv[iarg] << endl;
      exit(1);
    }
    iarg++;
  }
  if (mfname.size() == 0) mfname = ofname;
  ivector tvec(0);
  svector delims(0);
  svector dnames(0);
  nfields = parseFormat(ffname, tvec, dnames, delims, &grpsize);
  srivector srv(nfields);
  ftvector ftv(nfields);

  istream * ifstr;
  linebuf = new char[membuf];
  readbuf = new char[membuf];

  ifstr = open_in_buf(ifname, readbuf, membuf);

  while (!ifstr->bad() && !ifstr->eof()) {
    ifstr->getline(linebuf, membuf-1);
    linebuf[membuf-1] = 0;
    if (ifstr->fail()) {
      ifstr->clear();
      ifstr->ignore(LONG_MAX,'\n');
    }
    if (strlen(linebuf) > 0) {
      jmax++;
      try {
        parseLine(linebuf, membuf, ++iline, fdelim.c_str(), tvec, delims, srv, ftv, grpsize);
      } catch (int e) {
        cerr << "Continuing" << endl;
      }
    }
    if ((jmax % 100000) == 0) {
      cout<<"\r"<<jmax<<" lines processed";
      cout.flush();
    }
  }
  if (ifstr) delete ifstr;
  cout<<"\r"<<jmax<<" lines processed";
  cout.flush();

  for (i = 0; i < nfields; i++) {
    switch (tvec[i]) {
    case ftype_int: case ftype_dt: case ftype_mdt: case ftype_date: case ftype_mdate: case ftype_cmdate:
      ftv[i].writeInts(ofname + dnames[i] + ".imat" + suffix);
      break;
    case ftype_dint:
      ftv[i].writeDInts(ofname + dnames[i] + ".dimat" + suffix);
      break;
    case ftype_qhex:
      ftv[i].writeQInts(ofname + dnames[i] + ".imat" + suffix);
      break;
    case ftype_float:
      ftv[i].writeFloats(ofname + dnames[i] + ".fmat" + suffix);
      break;
    case ftype_double:
      ftv[i].writeDoubles(ofname + dnames[i] + ".dmat" + suffix);
      break;
    case ftype_word:
      ftv[i].writeInts(ofname + dnames[i] + ".imat" + suffix);
      srv[i].writeMap(mfname + dnames[i], suffix);
      break;
    case ftype_string: case ftype_group: 
      ftv[i].writeIVecs(ofname + dnames[i] + ".imat" + suffix);
      srv[i].writeMap(mfname + dnames[i], suffix);
      break;
    case ftype_igroup:
      ftv[i].writeIVecs(ofname + dnames[i] + ".imat" + suffix);
      break;
    case ftype_digroup:
      ftv[i].writeDIVecs(ofname + dnames[i]);
      break;
    default:
      break;
    }    
  }
  printf("\n");
  if (linebuf) delete [] linebuf;
  return 0;
}