예제 #1
0
int cuda_rpc_connect(struct cuda_rpc *rpc, const char *ip, const char *port)
{
#if defined(NIC_SDP)
	return conn_connect(&rpc->sockconn, ip, port, true);
#elif defined(NIC_ETHERNET)
	return conn_connect(&rpc->sockconn, ip, port, false);
#else
#error NIC_* not defined
#endif
}
예제 #2
0
static struct connection *conn_create_server(struct context *ctx, struct address *addr, char *key)
{
    int fd = conn_create_fd();
    if (fd == -1) {
        LOG(ERROR, "conn_create_server: fail to create fd");
        return NULL;
    }
    struct connection *server = server_create(ctx, fd);
    struct conn_info *info = server->info;
    memcpy(&info->addr, addr, sizeof(info->addr));

    if (conn_connect(server) == CORVUS_ERR) {
        LOG(ERROR, "conn_create_server: fail to connect %s:%d",
                info->addr.ip, info->addr.port);
        conn_free(server);
        conn_buf_free(server);
        conn_recycle(ctx, server);
        return NULL;
    }

    strncpy(info->dsn, key, DSN_LEN);
    dict_set(&ctx->server_table, info->dsn, (void*)server);
    TAILQ_INSERT_TAIL(&ctx->servers, server, next);
    return server;
}
예제 #3
0
static int verify_server(struct connection *server)
{
    if (server->info == NULL) {
        LOG(ERROR, "verify_server: connection info of server %d is null",
                server->fd);
        return CORVUS_ERR;
    }
    struct conn_info *info = server->info;
    if (info->status != DISCONNECTED) {
        return CORVUS_OK;
    }

    if (server->fd != -1) {
        close(server->fd);
    }

    server->fd = conn_create_fd();
    if (server->fd == -1) {
        LOG(ERROR, "verify_server: fail to create fd");
        conn_free(server);
        return CORVUS_ERR;
    }

    if (conn_connect(server) == CORVUS_ERR) {
        LOG(ERROR, "verify_server: fail to connect %s:%d",
                info->addr.ip, info->addr.port);
        conn_free(server);
        return CORVUS_ERR;
    }
    server->registered = false;
    return CORVUS_OK;
}
예제 #4
0
파일: mem.c 프로젝트: jyoung3131/oncilla
/* send then recv 1 message with rank */
  static int
send_recv_msg(struct message *msg, int rank)
{
  int ret = -1, i = 2;
  char port[HOST_NAME_MAX];
  struct sockconn conn;
  memset(&conn, 0, sizeof(conn));
  BUG(!msg);
  BUG(rank > node_file_entries - 1);
  snprintf(port, HOST_NAME_MAX, "%d", node_file[rank].ocm_port);
  if (conn_connect(&conn, node_file[rank].ip_eth, port))
    goto out;
  while (i-- > 0) {
    switch (i) {
      case 1: ret = conn_put(&conn, msg, sizeof(*msg)); break;
      case 0: ret = conn_get(&conn, msg, sizeof(*msg)); break;
    }
    if (--ret < 0) /* 0 means remote closed; turn into error condition */
      break;
  }
  if (ret < 0 || (ret = conn_close(&conn)))
    goto out;
  ret = 0;
out:
  /* TODO close connection on error */
  return ret;
}
예제 #5
0
static struct connection *conn_create_server(struct context *ctx,
        struct address *addr, char *key, bool readonly)
{
    int fd = conn_create_fd();
    if (fd == -1) {
        LOG(ERROR, "conn_create_server: fail to create fd");
        return NULL;
    }
    struct connection *server = server_create(ctx, fd);
    struct conn_info *info = server->info;
    memcpy(&info->addr, addr, sizeof(info->addr));
    extern const size_t CMD_NUM;
    info->slow_cmd_counts = cv_calloc(CMD_NUM, sizeof(uint32_t));

    if (conn_connect(server) == CORVUS_ERR) {
        LOG(ERROR, "conn_create_server: fail to connect %s:%d",
                info->addr.ip, info->addr.port);
        conn_free(server);
        conn_buf_free(server);
        conn_recycle(ctx, server);
        return NULL;
    }

    if (readonly) {
        server->info->readonly = true;
    }

    strncpy(info->dsn, key, ADDRESS_LEN);
    dict_set(&ctx->server_table, info->dsn, (void*)server);
    TAILQ_INSERT_TAIL(&ctx->servers, server, next);
    return server;
}
예제 #6
0
int main(int argc, char *argv[]) {

	Connection conn;
	char filename[MAX_FILENAME];
	int ctrl, first = TRUE;
	pid_t child;

	if (argc != 3) {
		fprintf(stderr, "syntax: %s <address> <port>\n", argv[0]);
		exit(-1);
	}

	//if (checkaddress(argv[1])) return -1;

	conn = conn_connect(argv[1], checkport(argv[2]));
	
	signal(SIGCHLD, signalHandler);
	signal(SIGINT, signalHandler);
	
	printf("Insert filename or <quit> to close the connection\n");
	
	while (TRUE) {
		
		readline(filename, MAX_FILENAME);

		if (!strcmp(filename, "Q") || !strcmp(filename, "q")) {
			printf("Terminating connection with server...\n");
			ctrl = conn_sends(conn, "QUIT\r\n");
			if (ctrl == -1) return -1;
			ctrl = conn_close(conn);
			if (ctrl == -1) return -1;
			return 0;
		}
		
		if (!strcmp(filename, "A") || !strcmp(filename, "a")) {
			printf("Aborting connection with server...\n");
			if (kill(child, SIGKILL))
				report_err("Cannot terminate a child");
			ctrl = conn_close(conn);
			if (ctrl == -1) return -1;
			return 0;
		}
		if (!first)
			wait(NULL);
		else 
			first = FALSE;
		
		child = fork();
		
		if (!child) {
			ctrl = requestFile(conn, filename);
			if (ctrl == -1) return -1; 
			return 0;
		}
	}

	return 0;
}
예제 #7
0
static int
connection_setup(connectionObject *self, const char *dsn, long int async)
{
    int rv = -1;

    Dprintf("connection_setup: init connection object at %p, "
	    "async %ld, refcnt = " FORMAT_CODE_PY_SSIZE_T,
            self, async, Py_REFCNT(self)
      );

    if (0 > psyco_strdup(&self->dsn, dsn, -1)) { goto exit; }
    if (!(self->notice_list = PyList_New(0))) { goto exit; }
    if (!(self->notifies = PyList_New(0))) { goto exit; }
    self->async = async;
    self->status = CONN_STATUS_SETUP;
    self->async_status = ASYNC_DONE;
    if (!(self->string_types = PyDict_New())) { goto exit; }
    if (!(self->binary_types = PyDict_New())) { goto exit; }
    self->isolevel = ISOLATION_LEVEL_DEFAULT;
    self->readonly = STATE_DEFAULT;
    self->deferrable = STATE_DEFAULT;
#ifdef CONN_CHECK_PID
    self->procpid = getpid();
#endif

    /* other fields have been zeroed by tp_alloc */

    if (0 != pthread_mutex_init(&(self->lock), NULL)) {
        PyErr_SetString(InternalError, "lock initialization failed");
        goto exit;
    }

    if (conn_connect(self, async) != 0) {
        Dprintf("connection_init: FAILED");
        goto exit;
    }

    rv = 0;

    Dprintf("connection_setup: good connection object at %p, refcnt = "
        FORMAT_CODE_PY_SSIZE_T,
        self, Py_REFCNT(self));

exit:
    /* here we obfuscate the password even if there was a connection error */
    {
        PyObject *ptype = NULL, *pvalue = NULL, *ptb = NULL;
        PyErr_Fetch(&ptype, &pvalue, &ptb);
        obscure_password(self);
        PyErr_Restore(ptype, pvalue, ptb);
    }
    return rv;
}
예제 #8
0
static int
connection_setup(connectionObject *self, const char *dsn, long int async)
{
    char *pos;
    int res;

    Dprintf("connection_setup: init connection object at %p, "
	    "async %ld, refcnt = " FORMAT_CODE_PY_SSIZE_T,
            self, async, ((PyObject *)self)->ob_refcnt
      );

    self->dsn = strdup(dsn);
    self->notice_list = PyList_New(0);
    self->notifies = PyList_New(0);
    self->closed = 0;
    self->async = async;
    self->status = CONN_STATUS_SETUP;
    self->critical = NULL;
    self->async_cursor = NULL;
    self->async_status = ASYNC_DONE;
    self->pgconn = NULL;
    self->mark = 0;
    self->string_types = PyDict_New();
    self->binary_types = PyDict_New();
    self->notice_pending = NULL;
    self->encoding = NULL;

    pthread_mutex_init(&(self->lock), NULL);

    if (conn_connect(self, async) != 0) {
        Dprintf("connection_init: FAILED");
        res = -1;
    }
    else {
        Dprintf("connection_setup: good connection object at %p, refcnt = "
            FORMAT_CODE_PY_SSIZE_T,
            self, ((PyObject *)self)->ob_refcnt
          );
        res = 0;
    }

    /* here we obfuscate the password even if there was a connection error */
    pos = strstr(self->dsn, "password");
    if (pos != NULL) {
        for (pos = pos+9 ; *pos != '\0' && *pos != ' '; pos++)
            *pos = 'x';
    }

    return res;
}
예제 #9
0
static int
connection_setup(connectionObject *self, const char *dsn)
{
    char *pos;
    int res;

    Dprintf("connection_setup: init connection object at %p, refcnt = "
        FORMAT_CODE_PY_SSIZE_T,
        self, ((PyObject *)self)->ob_refcnt
      );

    {
        size_t dsnlen = strlen(dsn) + 1;
        
        self->dsn = PyMem_Malloc(dsnlen);
        memmove(self->dsn, dsn, dsnlen);
    }
    self->notice_list = PyList_New(0);
    self->notifies = PyList_New(0);
    self->closed = 0;
    self->status = CONN_STATUS_READY;
    self->pgconn = NULL;
    self->mark = 0;
    self->string_types = PyDict_New();
    self->binary_types = PyDict_New();
    self->pg_io_timeout = 10.0;

    if (conn_connect(self) != 0) {
        Dprintf("connection_init: FAILED");
        res = -1;
    }
    else {
        Dprintf("connection_setup: good connection object at %p, refcnt = "
            FORMAT_CODE_PY_SSIZE_T,
            self, ((PyObject *)self)->ob_refcnt
          );
        res = 0;
    }

    /* here we obfuscate the password even if there was a connection error */
    pos = strstr(self->dsn, "password");
    if (pos != NULL) {
        for (pos = pos+9 ; *pos != '\0' && *pos != ' '; pos++)
            *pos = 'x';
    }

    return res;
}
예제 #10
0
static int
connection_setup(connectionObject *self, const char *dsn, long int async)
{
    char *pos;
    int res = -1;

    Dprintf("connection_setup: init connection object at %p, "
	    "async %ld, refcnt = " FORMAT_CODE_PY_SSIZE_T,
            self, async, Py_REFCNT(self)
      );

    if (!(self->dsn = strdup(dsn))) {
        PyErr_NoMemory();
        goto exit;
    }
    if (!(self->notice_list = PyList_New(0))) { goto exit; }
    if (!(self->notifies = PyList_New(0))) { goto exit; }
    self->async = async;
    self->status = CONN_STATUS_SETUP;
    self->async_status = ASYNC_DONE;
    if (!(self->string_types = PyDict_New())) { goto exit; }
    if (!(self->binary_types = PyDict_New())) { goto exit; }
    /* other fields have been zeroed by tp_alloc */

    pthread_mutex_init(&(self->lock), NULL);

    if (conn_connect(self, async) != 0) {
        Dprintf("connection_init: FAILED");
        goto exit;
    }
    else {
        Dprintf("connection_setup: good connection object at %p, refcnt = "
            FORMAT_CODE_PY_SSIZE_T,
            self, Py_REFCNT(self)
          );
        res = 0;
    }

    /* here we obfuscate the password even if there was a connection error */
    pos = strstr(self->dsn, "password");
    if (pos != NULL) {
        for (pos = pos+9 ; *pos != '\0' && *pos != ' '; pos++)
            *pos = 'x';
    }

exit:
    return res;
}
예제 #11
0
파일: bot.c 프로젝트: Detegr/CBot
int bot_connect(struct bot* b, const char* server, unsigned int port)
{
	if(conn_connect(b->conn, server, port)==0)
	{
		const char** nick = config_getvals(b->conf, "nick");
		const char** realname = config_getvals(b->conf, "realname");

		CMD(b->conn, "NICK", NULL, *nick);
		char name[64]; *name=0;
		concat(name, 5, *nick, " ", *nick, " * :", *realname);
		CMD(b->conn, "USER", NULL, name);

		return 0;
	}
	else
	{
		fprintf(stderr, "Couldn't connect to %s:%d\n", server, port);
		return -1;
	}
}
예제 #12
0
파일: mem.c 프로젝트: jyoung3131/oncilla
/* send 1 message to rank */
  static int
send_msg(struct message *msg, int rank)
{
  int ret = -1;
  char port[HOST_NAME_MAX];
  struct sockconn conn;
  memset(&conn, 0, sizeof(conn));
  BUG(!msg);
  BUG(rank > node_file_entries - 1);
  snprintf(port, HOST_NAME_MAX, "%d", node_file[rank].ocm_port);
  if (conn_connect(&conn, node_file[rank].ip_eth, port))
    goto out;
  ret = conn_put(&conn, msg, sizeof(*msg));
  if (--ret < 0) /* 0 means remote closed; turn into error condition */
    goto out;
  if ((ret = conn_close(&conn)))
    goto out;
  ret = 0;
out:
  return ret;
}