Ejemplo n.º 1
0
Archivo: rpc.c Proyecto: eroullit/dabba
ProtobufC_RPC_Server *dabbad_rpc_server_start(const char *const name,
					      const ProtobufC_RPC_AddressType
					      type)
{
	int rc = 0;
	ProtobufC_RPC_Server *server;

	assert(name);
	assert(strlen(name));
	assert(type == PROTOBUF_C_RPC_ADDRESS_LOCAL
	       || type == PROTOBUF_C_RPC_ADDRESS_TCP);

	server = protobuf_c_rpc_server_new(type, name,
					   (ProtobufCService *) & dabba_service,
					   NULL);

	if (server && type == PROTOBUF_C_RPC_ADDRESS_LOCAL) {
		rc = chmod(name, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP);

		if (rc) {
			dabbad_rpc_server_stop(server);
			server = NULL;
		}
	}

	return server;
}
Ejemplo n.º 2
0
int main(int argc, char**argv)
{
  ProtobufC_RPC_Server *server;
  ProtobufC_RPC_AddressType address_type=0;
  const char *name = NULL;
  unsigned i;

  for (i = 1; i < (unsigned) argc; i++)
    {
      if (starts_with (argv[i], "--port="))
        {
          address_type = PROTOBUF_C_RPC_ADDRESS_TCP;
          name = strchr (argv[i], '=') + 1;
        }
      else if (starts_with (argv[i], "--unix="))
        {
          address_type = PROTOBUF_C_RPC_ADDRESS_LOCAL;
          name = strchr (argv[i], '=') + 1;
        }
      else if (starts_with (argv[i], "--database="))
        {
          load_database (strchr (argv[i], '=') + 1);
        }
      else
        usage ();
    }

  if (database_size == 0)
    die ("missing --database=FILE (try --database=example.database)");
  if (name == NULL)
    die ("missing --port=NUM or --unix=PATH");
  
  signal (SIGPIPE, SIG_IGN);

  server = protobuf_c_rpc_server_new (address_type, name, (ProtobufCService *) &the_dir_lookup_service, NULL);

  for (;;)
    protobuf_c_rpc_dispatch_run (protobuf_c_rpc_dispatch_default ());
  return 0;
}