Example #1
0
int main(int argc, char* argv[]) {

	if (argc < 2 || argc > 3) {
		std::cerr << "Usage: " << argv[0] << " INFILE [OUTFILE]" << std::endl;
		exit(1);
	}

	std::string input_filename(argv[1]);
	std::string output_filename;
	if (argc != 3) {
		output_filename = std::string("out.sqlite");
	} else {
		output_filename = std::string(argv[2]);
	}

	{
	// from http://stackoverflow.com/questions/1647557/ifstream-how-to-tell-if-specified-file-doesnt-exist/3071528#3071528
	struct stat file_info;
	if (stat(output_filename.c_str(), &file_info) == 0) {
		std::cerr << "ERROR: Output file '" << output_filename << "' exists. Aborting..." << std::endl;
		exit(1);
	}
	}

	std::set<osmium::unsigned_object_id_type> addr_interpolation_node_set;
	name2highways_type name2highway;

	index_pos_type index_pos;
	index_neg_type index_neg;
	location_handler_type location_handler(index_pos, index_neg);
	//location_handler.ignore_errors();

	MemHelper mem_helper;
	//mem_helper.start();
	{
	osmium::io::Reader reader(input_filename);

	FirstHandler first_handler(addr_interpolation_node_set, name2highway);

	osmium::apply(reader, location_handler, first_handler);
	reader.close();
	}
	//mem_helper.stop();

	osmium::io::Reader reader2(input_filename);
	SecondHandler second_handler(output_filename, addr_interpolation_node_set, name2highway);
	osmium::apply(reader2, location_handler, second_handler);
	reader2.close();

	google::protobuf::ShutdownProtobufLibrary();

	std::cout << std::endl;
	mem_helper.print_max();

	std::cout << "\nsoftware finished properly\n" << std::endl;
	return 0;
}
Example #2
0
int
LibAliasUnLoadAllModule(void)
{
	struct dll *t;
	struct proto_handler *p;

	/* Unload all modules then reload everything. */
	while ((p = first_handler()) != NULL) {	
		detach_handler(p);
	}
	while ((t = walk_dll_chain()) != NULL) {	
		dlclose(t->handle);
		free(t);
	}
	return (1);
}
int server_create_listener_net(char* port, funCB funp)
{

  int fd=0, ret=-1, bufSize;
  char buf[MAX_BUF_SIZE];
//------------------------------------------------------
  int yes=1;
  struct addrinfo hints;
  struct addrinfo *result = NULL, *p;
//  conn_t* listenconn = (conn_t*)malloc(sizeof(conn_t));  // listen on sock_fd, new connection on new_fd

  memset(&hints, 0, sizeof(hints));
  hints.ai_family = AF_INET;
  hints.ai_socktype = SOCK_STREAM;
  hints.ai_flags = AI_PASSIVE;
  
  int status = getaddrinfo(NULL, port, &hints, &result);
  if (status != 0) {
    printf("getaddrinfo error: %s\n", gai_strerror(status));
    goto fun_exit;
  }
  
  // loop through all the results and bind to the first we can
  for(p = result; p != NULL; p = p->ai_next) {
    if ((fd = socket(p->ai_family, p->ai_socktype,
        p->ai_protocol)) == -1) {
        printf("could not create socket with this address, retrying...\n");
        continue;
       }
       if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &yes,
          sizeof(int)) == -1) {
          printf("setsockopt on this socket failed, retrying...\n");
          continue;//return -1;
       }
       if (bind(fd, p->ai_addr, p->ai_addrlen) == -1) {
          close(fd);
          printf("bind on this address failed, retrying...\n");
          continue;
       }
        break;
  }

  if (p == NULL) {
    fprintf(stderr, "failed to bind\n");
     goto fun_exit;
  }

  freeaddrinfo(result); // all done with this structure

  if (listen(fd, 10) == -1) {
    perror("could not listen\n");
    goto fun_exit;
  }
//------------------------------------------------------  
  fd_set rset;
  FD_ZERO(&rset);
  FD_SET(fd, &rset);
 
  while (1)
  {
    select(fd+1, &rset, NULL, NULL, NULL);
    if (FD_ISSET(fd, &rset))
    {
      bufSize = first_handler(fd, buf);

      //printf("<< %s,%d >>\n", buf, bufSize);
       funp((unsigned char *)buf,bufSize);
    }
  }
  ret = 0;
//------------------------------------------------------

fun_exit:
  printf("listen failed\n");
  if (fd>0) close(fd);
  return ret;
}
int server_create_listener(char* name,  funCB funp)
{
  int fd, ret=-1, bufSize;
  struct sockaddr_un saddr;
  struct sockaddr_un from;
  char buf[MAX_BUF_SIZE];
 
  /* open a socket */
  if ((fd = socket(AF_UNIX, SOCK_STREAM, 0)) < 0)
  {
    printf("socket failed\n");
    goto fun_exit;
  }
  
  /* set the addr */
  unlink(name);
  bzero(&saddr, sizeof(saddr));
  saddr.sun_family = AF_UNIX;
  strcpy(saddr.sun_path, name);
 
  /* bind socket with addr */
  if (bind(fd, (struct sockaddr*)&saddr, sizeof(saddr)) < 0)
  {
    printf("bind failed\n");
    goto fun_exit;
  }
  
  /* listen fd */
  if (listen(fd, 10) < 0)
  {
    printf("listen failed\n");
    goto fun_exit;
  }
 
  fd_set rset;
  FD_ZERO(&rset);
  FD_SET(fd, &rset);
 
  struct  timeval timeout;

  while (ServerFlag)
  {
    timeout.tv_sec = SERVER_CHECK_TIMEOUT; 
    timeout.tv_usec = 0; 

    FD_ZERO(&rset); 
    FD_SET(fd,&rset); 

    int reveal = select(fd+1, &rset, NULL, NULL, &timeout);

    if (reveal <= 0) 
    { 
         printf("<server timeout>(%s)\n",name);
       // quitProgram(number); /* error or connection timed out */
    } 
    else{ 
      if (FD_ISSET(fd, &rset))
      {
        bufSize = first_handler(fd, buf);
        funp((unsigned char *)buf,bufSize);
      }
    }

  }
  ret = 0;
 
fun_exit:
   printf("listen failed\n");
  if (fd>0) close(fd);
  return ret;
}