Example #1
0
static void
ob_server_func (GServer* server, GConn* conn, gpointer user_data)
{
  if (conn)
    {
      gnet_conn_set_callback (conn, ob_client_func, NULL);
      gnet_conn_set_watch_error (conn, TRUE);
      gnet_conn_readline (conn);
    }
  else	/* Error */
    {
      gnet_server_delete (server);
      exit (EXIT_FAILURE);
    }
}
Example #2
0
void              remote_server_main_loop     (int        port_number,
					       gboolean   have_gtk,
					       gboolean   verbose)
{
    RemoteServer self;

    self.have_gtk = have_gtk;
    self.verbose = verbose;

    self.gserver = gnet_server_new(NULL, port_number,
				   remote_server_connect, &self);
    if (!self.gserver) {
	printf("Unable to listen on port %d!\n", port_number);
	exit(1);
    }

    self.command_hash = g_hash_table_new(g_str_hash, g_str_equal);
    self.gui_hash = g_hash_table_new(g_str_hash, g_str_equal);
    remote_server_init_commands(&self);

    if (self.verbose)
	printf("Fyre server listening on port %d\n", port_number);

    /* At this point, now that we've bound to the port and such,
     * make sure we aren't running as a privileged user. If so,
     * ditch all privileges permanently.
     */
    release_privileges(&self);

    if (have_gtk)
	gtk_main();
    else
	g_main_loop_run(g_main_loop_new(NULL, FALSE));

    if (self.verbose)
	printf("Fyre server shutting down.\n");

    gnet_server_delete(self.gserver);
    g_hash_table_destroy(self.command_hash);
    g_hash_table_destroy(self.gui_hash);
}
Example #3
0
static void ob_server_func (GServer* server, GServerStatus status, struct _GConn* conn, gpointer user_data)
{
  switch (status)
    {
    case GNET_SERVER_STATUS_CONNECT:
      {
        if (debug) {
          LOG(LOG_DEBUG, "New connection from %s", gnet_inetaddr_get_canonical_name(conn->inetaddr));
        }
        conn->func = ob_client_func;
        conn->user_data = calloc(1, sizeof(struct conn_stat));
        gnet_conn_write (conn, strdup(hello), strlen(hello), 0);
        gnet_conn_readline (conn, NULL, 1024, 30000);
        break;
      }

    case GNET_SERVER_STATUS_ERROR:
      {
        gnet_server_delete (server);
        exit (1);
        break;
      }
    }
}
Example #4
0
static void ob_sig_term (int signum)
{
  gnet_server_delete (ob_server);
  exit (1);
}
Example #5
0
static void 
ob_sig_int (int signum)
{
  gnet_server_delete (ob_server);
  exit (EXIT_FAILURE);
}