示例#1
0
文件: sockconn.cpp 项目: kmillar/rho
static Rboolean sock_open(Rconnection con)
{
    Rsockconn thisconn = (Rsockconn)con->connprivate;
    int sock, sock1, mlen;
    int timeout = thisconn->timeout;
    char buf[256];

    if(timeout == NA_INTEGER || timeout <= 0) timeout = 60;
    thisconn->pend = thisconn->pstart = thisconn->inbuf;

    if(thisconn->server) {
	sock1 = R_SockOpen(thisconn->port);
	if(sock1 < 0) {
	    warning("port %d cannot be opened", thisconn->port);
	    return FALSE;
	}
	/* use try-catch to close socket on jump. */
	try {
	    sock = R_SockListen(sock1, buf, 256, timeout);
	}
	catch (...) {
	    R_SockClose(sock1);
	    throw;
	}

	if(sock < 0) {
	    warning("problem in listening on this socket");
	    R_SockClose(sock1);
	    return FALSE;
	}
	free(con->description);
	con->description = (char *) malloc(strlen(buf) + 10);
	sprintf(con->description, "<-%s:%d", buf, thisconn->port);
	R_SockClose(sock1);
    } else {
	sock = R_SockConnect(thisconn->port, con->description, timeout);
	if(sock < 0) {
	    warning("%s:%d cannot be opened", con->description, thisconn->port);
	    return FALSE;
	}
	sprintf(buf, "->%s:%d", con->description, thisconn->port);
	strcpy(con->description, buf);
    }
    thisconn->fd = sock;

    mlen = int( strlen(con->mode));
    con->isopen = TRUE;
    if(mlen >= 2 && con->mode[mlen - 1] == 'b') con->text = FALSE;
    else con->text = TRUE;
    set_iconv(con); /* OK for output, at least */
    con->save = -1000;
    return TRUE;
}
示例#2
0
文件: sockconn.cpp 项目: kmillar/rho
static void sock_close(Rconnection con)
{
    Rsockconn thisconn = (Rsockconn)con->connprivate;
    R_SockClose(thisconn->fd);
    con->isopen = FALSE;
}
示例#3
0
文件: sockconn.c 项目: Maxsl/r-source
static void listencleanup(void *data)
{
    int *psock = data;
    R_SockClose(*psock);
}