コード例 #1
0
ファイル: stubd.c プロジェクト: senseisimple/emulab-stable
void init(void) {
  int i;

  for (i = 0; i < CONCURRENT_RECEIVERS; i++)
  {
      add_empty_receiver(i);
      init_connection(& rcvdb[i]);
  }
  for (i = 0; i < CONCURRENT_SENDERS; i++)
  {
      add_empty_sender(i);
      init_connection(& snddb[i]);
  }
}
コード例 #2
0
ファイル: flask_engine.c プロジェクト: hongjaic/15-441-p2
/*
 * flask_request_handler - Processes incoming flask request. Pareses the
 * request and builds response depending on process results.
 *
 * @param i client socket identifier
 * @return  1 when successful, 0 otherwise
 */
int flask_request_handler(int i)
{
    int no_data_read = 0;
    int readret;
    int errnoSave;
    tcp_connection *curr_connection = &((engine.connections)[i]);

    memset(engine.buf, 0, BUF_SIZE);
    readret = recv(i, engine.buf, BUF_SIZE - curr_connection->request_index, 0);

    if (readret == 0)
    {
        init_connection(curr_connection);
        close(i);
        FD_CLR(i,&(engine.rfds));
        FD_CLR(i,&(engine.wfds));
        return 0;
    }
    else if (readret < 1)
    {
        errnoSave = errno;

        if (errnoSave == ECONNRESET)
        {
            init_connection(curr_connection);
            close(i);
            fprintf(stderr, "Client disconneted.\n");
            return -1;
        }
        else
        {
            curr_connection->status = 500;
            build_response(curr_connection);
            FD_SET(i, &(engine.wfds));
            no_data_read = 1;
        }
    }

    if (no_data_read == 0)
    {
        memcpy(curr_connection->request, engine.buf, readret);
        curr_connection->request_index = readret;
        curr_connection->status = 200;
        process_buffer(curr_connection, i);
        build_response(curr_connection);
        FD_SET(i, &(engine.wfds));
    }

    return 1;
}
コード例 #3
0
ShellXcb::ShellXcb(Game &game) : Shell(game)
{
    instance_extensions_.push_back(VK_KHR_XCB_SURFACE_EXTENSION_NAME);

    init_connection();
    init_vk();
}
コード例 #4
0
ファイル: ani_net.cpp プロジェクト: fadan/ani
inline void init_server_connection(Connection *connection, i16 port)
{
    init_connection(connection, port);

    connection->state  = ConnectionState_Listening;
    connection->is_server = true;
}
コード例 #5
0
ファイル: server.c プロジェクト: Dim-ka/countctl
int main(int argc, char *argv[]){

	struct srv_connection conn;
	int cli_ct;

	FILE *fin;

	if (argc!=3) {
		printf("Bad param\n");
		return 1;
	}

	cli_ct = atoi(argv[2]);

	fin = fopen(argv[1], "r");
	if (fin == NULL) {
		printf("err file");
		return 1;
	}

	make_daemon(argv[1]);

	create_workers(cli_ct);
	
	init_connection(&conn, cli_ct);

	process_file(fin, &conn);

	fclose(fin);

	close_connection(&conn);

	return 0;
}
コード例 #6
0
ファイル: sock.c プロジェクト: echoline/util
int main(int argc, char **argv) {
	for (int i = 1; i < argc; i++) {
		char buf[1024];
		int r, sock = init_connection(argv[i]);
		if (sock == -1) {
			printf("usage: sock [address]\n");
			continue;
		}
		switch(fork()) {
		case 0:
			while ((r = read(sock, buf, sizeof(buf))) > -1) {
				write(1, buf, r);
				fflush(stdout);
			}
			perror("read");
			return 0;
		case -1:
			perror("fork");
			break;
		default:
			while (fgets(buf, sizeof(buf), stdin)) {
				r = write(sock, buf, strlen(buf));
				if (r < 0) perror("write");
			}
			close(sock);
		}
	}
}
コード例 #7
0
ファイル: client.c プロジェクト: neokeld/Playground
static void app(const char *address, const char *name)
{
    SOCKET sock = init_connection(address);
    char buffer[BUF_SIZE];

    fd_set rdfs;

    /* le client envoie son nom */
    write_server(sock, name);

    while(1)
    {
	FD_ZERO(&rdfs);

	/* ajouter un STDIN_FILENO */
	FD_SET(STDIN_FILENO, &rdfs);

	/* ajouter le socket */
	FD_SET(sock, &rdfs);

	if(select(sock + 1, &rdfs, NULL, NULL, NULL) == -1)
	{
	    perror("select()");
	    exit(errno);
	}

	/* quelque chose qui vient du clavier */
	if(FD_ISSET(STDIN_FILENO, &rdfs))
	{
	    fgets(buffer, BUF_SIZE - 1, stdin);
	    {
		char *p = NULL;
		p = strstr(buffer, "\n");
		if(p != NULL)
		{
		    *p = 0;
		}
		else
		{
		    /* fclean */
		    buffer[BUF_SIZE - 1] = 0;
		}
	    }
	    write_server(sock, buffer);
	}
	else if(FD_ISSET(sock, &rdfs))
	{
	    int n = read_server(sock, buffer);
	    /* Si le serveur est down */
	    if(n == 0)
	    {
		/* On arrête */
		break;
	    }
	    puts(buffer);
	}
    }

    end_connection(sock);
}
コード例 #8
0
int main()
{
    int i; 
    int pri;
    IBP_REQUESTS_QUEUE * queue;
    IBP_REQUEST_POOL * pool;
    IBP_REQUEST *request;
    IBP_CONNECTION *conn;

    queue = init_req_queue(1024,400);
    glbReqPool = init_request_pool();
    for (i=0; i< 1024;i++){
        conn = init_connection(i);
        request = create_request(conn);
        set_request_priority(request,random()%400);
        append_request(queue,request);
    }

    for(i=0; i< 1024; i++){
        request=get_request(queue);
        free_request(pool,request);
    }


    fprintf(stderr,"Total allocated  = %d idle request = %d\n",
                    glbReqPool->allocated,glbReqPool->num);
    delete_req_queue(queue);
    delete_request_pool(glbRequestPool);

    return 0;
}
コード例 #9
0
ファイル: client.c プロジェクト: athomaj/my_ftp
int			main(int argc, char **argv)
{
  struct protoent	*pe;
  int			fd;
  struct sockaddr_in	s_in;
  int			port;
  char			*ip;

  if (argc != 3)
    {
      fprintf(stderr, "Usage: ./client ip port\n");
      return (-1);
    }
  ip = argv[1];
  port = atoi(argv[2]);
  if ((pe = getprotobyname("TCP")) == NULL)
    return (-1);
  s_in.sin_family = AF_INET;
  s_in.sin_port = htons(port);
  s_in.sin_addr.s_addr = inet_addr(ip);
  if ((fd = socket(AF_INET, SOCK_STREAM, pe->p_proto)) == -1)
    return (-1);
  init_connection(&s_in, fd);
  if (close(fd) == -1)
    return (-1);
  return (0);
}
コード例 #10
0
ファイル: client.c プロジェクト: Sconso/Irc
void				be_client(char *ip, int port)
{
	t_socket		sock;
	fd_set			rdfs;
	char			*ask;
	char			*prompt;

	sock = init_connection(ip, port);
	while (1)
	{
		init_socks(sock, &rdfs);
		if (FD_ISSET(STDIN_FILENO, &rdfs))
			client_in(sock);
		else if (FD_ISSET(sock, &rdfs))
		{
			client_out(sock);
			ask = ft_strdup("/gp\n");
			ft_send(sock, ask);
			free(ask);
			prompt = get_message(sock);
			ft_putstr("\n");
			ft_putstr(prompt);
			free(prompt);
		}
	}
}
コード例 #11
0
int init_connection_pair(struct connection_pair *c, int x)
{
	int i;
	void *p;

	init_connection(&c->local);

	if((c->remote = (void *) malloc(sizeof(struct connection) * x)) == NULL)
		return -1;

	for(i = 0, p = c->remote; i < x; ++i)
		init_connection((p + (i * sizeof(struct connection))));

	c->n_remote= x;
	return 0;
}
コード例 #12
0
void
vsf_two_process_start(struct vsf_session* p_sess)
{
  /* Create the comms channel between privileged parent and no-priv child */
  priv_sock_init(p_sess);
  vsf_sysutil_install_async_sighandler(kVSFSysUtilSigCHLD, handle_sigchld);
  {
    int newpid = vsf_sysutil_fork();
    if (newpid != 0)
    {
      /* Parent - go into pre-login parent process mode */
      while (1)
      {
        process_login_req(p_sess);
      }
      /* NOTREACHED */
      bug("should not get here: vsf_two_process_start");
    }
  }
  /* Child process - time to lose as much privilege as possible and do the
   * login processing
   */
  if (tunable_local_enable && tunable_userlist_enable)
  {
    int retval = str_fileread(&p_sess->userlist_str, tunable_userlist_file,
                              VSFTP_CONF_FILE_MAX);
    if (vsf_sysutil_retval_is_error(retval))
    {
      die("cannot open user list file");
    }
  }
  drop_all_privs();
  init_connection(p_sess);
  /* NOTREACHED */
}
コード例 #13
0
ファイル: server_widget.cpp プロジェクト: mbasaglia/RconGui
ServerWidget::ServerWidget(xonotic::ConnectionDetails details, QWidget* parent)
    : QWidget(parent), connection(std::move(details))
{
    menu_quick_commands = new QMenu(tr("Quick Commands"), this);
    menu_quick_commands->setObjectName("menu_quick_commands");

    setupUi(this);
    button_refresh_status->setShortcut(QKeySequence::Refresh);
    button_refresh_cvars->setShortcut(QKeySequence::Refresh);

    delayed_status.setInterval(150); /// \todo read from settings?
    delayed_status.setSingleShot(true);
    connect(&delayed_status, &QTimer::timeout, this, &ServerWidget::request_status);

    init_status_table();

    init_cvar_table();

    init_player_table();

    init_console();

    init_connection();

    reload_settings();
}
コード例 #14
0
ファイル: toxic.c プロジェクト: gracchus163/toxic
static void do_connection(Tox *m, ToxWindow *prompt)
{
    char msg[MAX_STR_SIZE] = {0};

    static int conn_err = 0;
    static bool was_connected = false;
    static uint64_t last_conn_try = 0;
    uint64_t curtime = get_unix_time();
    bool is_connected = tox_isconnected(m);

    if (was_connected && is_connected)
        return;

    if (!was_connected && is_connected) {
        was_connected = true;
        prompt_update_connectionstatus(prompt, was_connected);
        snprintf(msg, sizeof(msg), "DHT connected.");
    } else if (was_connected && !is_connected) {
        was_connected = false;
        prompt_update_connectionstatus(prompt, was_connected);
        snprintf(msg, sizeof(msg), "DHT disconnected. Attempting to reconnect.");
    } else if (!was_connected && !is_connected && timed_out(last_conn_try, curtime, TRY_CONNECT)) {
        /* if autoconnect has already failed there's no point in trying again */
        if (conn_err == 0) {
            last_conn_try = curtime;

            if ((conn_err = init_connection(m)) != 0)
                snprintf(msg, sizeof(msg), "Auto-connect failed with error code %d", conn_err);
        }
    }

    if (msg[0])
        line_info_add(prompt, NULL, NULL, NULL, SYS_MSG, 0, 0, msg);
}
コード例 #15
0
ファイル: webclient.c プロジェクト: ichpuchtli/freeburn
/*-----------------------------------------------------------------------------------*/
unsigned char
webclient_get(char *host, u16_t port, char *file)
{
  struct uip_conn *conn;
  uip_ipaddr_t *ipaddr;
  static uip_ipaddr_t addr;
  
  /* First check if the host is an IP address. */
  ipaddr = &addr;
  if(uiplib_ipaddrconv(host, (unsigned char *)addr) == 0) {
    ipaddr = (uip_ipaddr_t *)resolv_lookup(host);
    
    if(ipaddr == NULL) {
      return 0;
    }
  }
  
  conn = uip_connect(ipaddr, htons(port));
  
  if(conn == NULL) {
    return 0;
  }
  
  s.port = port;
  strncpy(s.file, file, sizeof(s.file));
  strncpy(s.host, host, sizeof(s.host));
  
  init_connection();
  return 1;
}
コード例 #16
0
ファイル: webclient.c プロジェクト: Asterios/contiki-econotag
/*-----------------------------------------------------------------------------------*/
unsigned char
webclient_get(const char *host, u16_t port, const char *file)
{
  uip_ipaddr_t addr;
  struct uip_conn *conn;
  uip_ipaddr_t *ipaddr;
  
  /* First check if the host is an IP address. */
  ipaddr = &addr;
  if(uiplib_ipaddrconv(host, &addr) == 0) {
#if UIP_UDP
    ipaddr = resolv_lookup(host);
    
    if(ipaddr == NULL) {
      return 0;
    }
#else /* UIP_UDP */
    return 0;
#endif /* UIP_UDP */
  }
  
  conn = tcp_connect(ipaddr, uip_htons(port), NULL);
  
  if(conn == NULL) {
    return 0;
  }
  
  s.port = port;
  strncpy(s.file, file, sizeof(s.file));
  strncpy(s.host, host, sizeof(s.host));
  
  init_connection();
  return 1;
}
コード例 #17
0
/**
 * Entry point for the plugin.
 *
 * @param cls the `struct GNUNET_DATASTORE_PluginEnvironment*`
 * @return our `struct Plugin *`
 */
void *
libgnunet_plugin_datastore_postgres_init (void *cls)
{
  struct GNUNET_DATASTORE_PluginEnvironment *env = cls;
  struct GNUNET_DATASTORE_PluginFunctions *api;
  struct Plugin *plugin;

  plugin = GNUNET_new (struct Plugin);
  plugin->env = env;
  if (GNUNET_OK != init_connection (plugin))
  {
    GNUNET_free (plugin);
    return NULL;
  }
  api = GNUNET_new (struct GNUNET_DATASTORE_PluginFunctions);
  api->cls = plugin;
  api->estimate_size = &postgres_plugin_estimate_size;
  api->put = &postgres_plugin_put;
  api->update = &postgres_plugin_update;
  api->get_key = &postgres_plugin_get_key;
  api->get_replication = &postgres_plugin_get_replication;
  api->get_expiration = &postgres_plugin_get_expiration;
  api->get_zero_anonymity = &postgres_plugin_get_zero_anonymity;
  api->get_keys = &postgres_plugin_get_keys;
  api->drop = &postgres_plugin_drop;
  GNUNET_log_from (GNUNET_ERROR_TYPE_INFO, "datastore-postgres",
                   _("Postgres database running\n"));
  return api;
}
コード例 #18
0
ファイル: flask_engine.c プロジェクト: hongjaic/15-441-p2
/*
 * flask_response_handler - Handles sending response to client and does
 * necessary clean up.
 *
 * @param i client socket identifier
 * @return  1 when successful. Simply exits when fatal error occurs.
 */
int flask_response_handler(int i)
{
    int errnoSave;
    int ret;
    tcp_connection *curr_connection = &((engine.connections)[i]);

    ret = send(i, curr_connection->response, curr_connection->response_index, MSG_NOSIGNAL);

    if (ret < 1)
    {
        errnoSave = errno;

        if (errnoSave != EPIPE && errnoSave != ECONNRESET)
        {
            close(i);
            close(engine.udp_sock);
            close(engine.tcp_sock);
            collapse(&gol);
            exit(EXIT_FAILURE);
        }
    }

    init_connection(curr_connection);
    FD_CLR(i, &(engine.rfds));
    FD_CLR(i, &(engine.wfds));
    close(i);

    return 1;
}
コード例 #19
0
ファイル: input.c プロジェクト: regina/uchat
void
input_connect(const char *arg) {
  int online;
  init_connection("irc.freenode.net", 6667, online);
  gui_update_statuswin(online);
  return;
}
コード例 #20
0
ファイル: main.c プロジェクト: stqism/toxic
static void do_connection(Tox *m, ToxWindow *prompt)
{
    uint8_t msg[MAX_STR_SIZE] = {0};

    static int conn_try = 0;
    static int conn_err = 0;
    static bool dht_on = false;

    bool is_connected = tox_isconnected(m);

    if (!dht_on && !is_connected && !(conn_try++ % 100)) {
        if (!conn_err) {
            if ((conn_err = init_connection(m))) {
                snprintf(msg, sizeof(msg), "\nAuto-connect failed with error code %d", conn_err);
            }
        }
    } else if (!dht_on && is_connected) {
        dht_on = true;
        prompt_update_connectionstatus(prompt, dht_on);
        snprintf(msg, sizeof(msg), "DHT connected.");
    } else if (dht_on && !is_connected) {
        dht_on = false;
        prompt_update_connectionstatus(prompt, dht_on);
        snprintf(msg, sizeof(msg), "\nDHT disconnected. Attempting to reconnect.");
    }

    if (msg[0])
        line_info_add(prompt, NULL, NULL, NULL, msg, SYS_MSG, 0, 0);
}
コード例 #21
0
static void app(const char *address, const char *name)
{
   SOCKET sock = init_connection(address);
   char buffer[BUF_SIZE];

   fd_set rdfs;

   /* send our name */
   write_server(sock, name);

   while(1)
   {
      FD_ZERO(&rdfs);

      /* add STDIN_FILENO */
      FD_SET(STDIN_FILENO, &rdfs);

      /* add the socket */
      FD_SET(sock, &rdfs);

      if(select(sock + 1, &rdfs, NULL, NULL, NULL) == -1)
      {
         perror("select()");
         exit(errno);
      }

      /* something from standard input : i.e keyboard */
      if(FD_ISSET(STDIN_FILENO, &rdfs))
      {
         fgets(buffer, BUF_SIZE - 1, stdin);
         {
            char *p = NULL;
            p = strstr(buffer, "\n");
            if(p != NULL)
            {
               *p = 0;
            }
            else
            {
               /* fclean */
               buffer[BUF_SIZE - 1] = 0;
            }
         }
         write_server(sock, buffer);
      }
      else if(FD_ISSET(sock, &rdfs))
      {
         int n = read_server(sock, buffer);
         /* server down */
         if(n == 0)
         {
            printf("Server disconnected !\n");
            break;
         }
         puts(buffer);
      }
   }

   end_connection(sock);
}
コード例 #22
0
ShellXcb::ShellXcb(Game &game) : Shell(game) {
    if (game.settings().validate) instance_layers_.push_back("VK_LAYER_LUNARG_standard_validation");
    instance_extensions_.push_back(VK_KHR_XCB_SURFACE_EXTENSION_NAME);

    init_connection();
    init_vk();
}
コード例 #23
0
/**
 * Entry point for the plugin.
 *
 * @param cls closure (the `struct GNUNET_DATACACHE_PluginEnvironmnet`)
 * @return the plugin's closure (our `struct Plugin`)
 */
void *
libgnunet_plugin_datacache_postgres_init (void *cls)
{
  struct GNUNET_DATACACHE_PluginEnvironment *env = cls;
  struct GNUNET_DATACACHE_PluginFunctions *api;
  struct Plugin *plugin;

  plugin = GNUNET_new (struct Plugin);
  plugin->env = env;

  if (GNUNET_OK != init_connection (plugin))
  {
    GNUNET_free (plugin);
    return NULL;
  }

  api = GNUNET_new (struct GNUNET_DATACACHE_PluginFunctions);
  api->cls = plugin;
  api->get = &postgres_plugin_get;
  api->put = &postgres_plugin_put;
  api->del = &postgres_plugin_del;
  api->get_random = &postgres_plugin_get_random;
  api->get_closest = &postgres_plugin_get_closest;
  LOG (GNUNET_ERROR_TYPE_INFO,
       "Postgres datacache running\n");
  return api;
}
コード例 #24
0
ファイル: main.c プロジェクト: FullName/toxic
static void do_tox(Tox *m, ToxWindow *prompt)
{
    static int conn_try = 0;
    static int conn_err = 0;
    static bool dht_on = false;

    if (!dht_on && !tox_isconnected(m) && !(conn_try++ % 100)) {
        if (!conn_err) {
            conn_err = init_connection(m);
            wprintw(prompt->window, "\nEstablishing connection...\n");

            if (conn_err)
                wprintw(prompt->window, "\nAuto-connect failed with error code %d\n", conn_err);
        }
    } else if (!dht_on && tox_isconnected(m)) {
        dht_on = true;
        prompt_update_connectionstatus(prompt, dht_on);
        wprintw(prompt->window, "\nDHT connected.\n");
    } else if (dht_on && !tox_isconnected(m)) {
        dht_on = false;
        prompt_update_connectionstatus(prompt, dht_on);
        wprintw(prompt->window, "\nDHT disconnected. Attempting to reconnect.\n");
    }

    tox_do(m);
}
コード例 #25
0
ファイル: ani_net.cpp プロジェクト: fadan/ani
inline void init_client_connection(Connection *connection, u16 client_port, u32 server_ip, u16 server_port)
{
    init_connection(connection, client_port);

    connection->state = ConnectionState_Connecting;
    connection->ip    = server_ip;
    connection->port  = server_port;
}
コード例 #26
0
__attribute__((constructor)) static void _liblogfaf_init(void) {
    DBG(("liblogfaf: init()\n"));
    init_progname(&shared_data);
    init_hostname(&shared_data);
    init_connection(&shared_data);
    pthread_mutex_init(&shared_data.lock, NULL);
    set_defaults(&shared_data);
}
コード例 #27
0
ファイル: location.cpp プロジェクト: cyclefusion/szarp
void Location::swap_connection( Location& loc )
{
	loc.sig_conn.disconnect();
	sig_conn.disconnect();

	std::swap( connection , loc.connection );

	loc.init_connection();
	init_connection();
}
コード例 #28
0
YJDouyuBarrage::YJDouyuBarrage(QWidget *parent)
	: QMainWindow(parent)
{
	m_clientTypeCount = new ClientTypeCount;
	ui.setupUi(this);
	init_tcp();

	init_keepAlive_thread();
	init_connection();
}
コード例 #29
0
ファイル: app.c プロジェクト: psychoss/android-comic
jstring
Java_euphoria_psycho_comic_util_Utilities_request(JNIEnv *env, jstring host, jstring path) {
    const char *n_host = (*env)->GetStringUTFChars(env, host, 0);
    const char *n_path = (*env)->GetStringUTFChars(env, path, 0);
    LOGW("%s",n_host);



    Buffer *response = buffer_alloc(255);

    int status = 0;
    int sockfd = 0;
    struct addrinfo *res = NULL;

    status = init_connection(n_host, "80", &res);
    error_unless(status == 0, "Could not resolve host: %s\n", gai_strerror(status));

    jstring result1 = (*env)->NewStringUTF(env, n_host);

    return result1;
    sockfd = make_connection(res);
    error_unless(sockfd > 0, "Could not make connection to '");

    status = make_request(sockfd, n_host, n_path);
    error_unless(status > 0, "Sending request failed");

    status = fetch_response(sockfd, &response, RECV_SIZE);
    error_unless(status >= 0, "Fetching response failed");

    printf("%s\n", response->contents);

    close(sockfd);

    freeaddrinfo(res);
    jstring result = (*env)->NewStringUTF(env, response->contents);
    buffer_free(response);
    (*env)->ReleaseStringUTFChars(env, host, n_host);
    (*env)->ReleaseStringUTFChars(env, path, n_path);

    return result;

    error:
    if (sockfd > 0) { close(sockfd); }
    if (res != NULL) { freeaddrinfo(res); }
    (*env)->ReleaseStringUTFChars(env, host, n_host);
    (*env)->ReleaseStringUTFChars(env, path, n_path);
    return (*env)->NewStringUTF(env, "Error");


    buffer_free(response);
//    return (*env)->NewStringUTF(env, "Hello from JNI !  Compiled with ABI "
//    ABI
//    ".");
}
コード例 #30
0
ファイル: test.c プロジェクト: Jin-W-FS/epoll-test
myconn_t* new_connection(int fd, event_handler_t* handler, void* arg)
{
	int i;
	for (i = 0; i < sizeof(connection_poll) / sizeof(connection_poll[0]); i++) {
		if (connection_poll[i].status == 0) {
			init_connection(&connection_poll[i], fd, handler, arg);
			return &connection_poll[i];
		}
	}
	return NULL;
}