当前位置: 首页>>代码示例>>C++>>正文


C++ sock_close函数代码示例

本文整理汇总了C++中sock_close函数的典型用法代码示例。如果您正苦于以下问题:C++ sock_close函数的具体用法?C++ sock_close怎么用?C++ sock_close使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了sock_close函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: send_packet

/* send one packet (heartbeat) */
int send_packet(void)
{
	static long sequence;
	auto char 	buf[128];
	auto int 	length, retval;

	#GLOBAL_INIT
	{
		sequence = 0;
	}

	/* fill the packet with interesting data (a sequence number) */
	sequence++;
	sprintf(buf, "SEQ=%ld",sequence);
	length = strlen(buf) + 1;

	/* send the packet */
	retval = udp_send(&sock, buf, length);
	if (retval < 0) {
		printf("Error sending datagram!  Closing and reopening socket...\n");
		if (sequence == 1) {
			printf("   (initial ARP request may not have finished)\n");
		}
		sock_close(&sock);
		if(!udp_open(&sock, LOCAL_PORT, resolve(REMOTE_IP), REMOTE_PORT, NULL)) {
			printf("udp_open failed!\n");
			exit(0);
		}
	}

	tcp_tick(NULL);	
	return 1;
}
开发者ID:jgambox,项目名称:DCRabbit_9,代码行数:34,代码来源:Udp_cli.c

示例2: connection_close

void connection_close(connection_t *con)
{
    sock_close(con->sock);
    if (con->ip) free(con->ip);
    if (con->host) free(con->host);
    free(con);
}
开发者ID:kitsune-dsu,项目名称:kitsune-icecast,代码行数:7,代码来源:connection.c

示例3: sock_server_create

int sock_server_create(struct sockaddr *addr)
{
	int fd;
	int ret;

	fd = sock_create();
	if(fd < 0) {
		return -1;
	}

	ret = sock_set_reuseaddr(fd);
	if(ret < 0) {
		goto err_server;
	}

	ret = sock_bind(fd, addr);
	if(ret < 0) {
		goto err_server;
	}

	ret = sock_listen(fd);
	if(ret < 0) {
		goto err_server;
	}

	return fd;

err_server:
	sock_close(fd);

	return -1;
}
开发者ID:forthewatch,项目名称:xdm,代码行数:32,代码来源:sock.c

示例4: udpServerCreate

SOCKET udpServerCreate (struct in_addr * localip, int port)
{
	SOCKET	fd;
	struct sockaddr_in addr;

	fd = socket(AF_INET, SOCK_DGRAM, 0);
	if (fd == -1) {
		return EF_INVALID_SOCKET;
	}

	memset(&addr, 0, sizeof(struct sockaddr_in));

	addr.sin_family = AF_INET;
	if (localip != NULL) {
		addr.sin_addr = *localip;
	}
	else {
		addr.sin_addr.s_addr = htonl(INADDR_ANY);	
	}
	addr.sin_port = htons(port);

	if (bind(fd, (struct sockaddr *)&addr, sizeof(struct sockaddr)) != 0) {
		sock_close(fd);
		return EF_INVALID_SOCKET;
	}


	return fd;
}
开发者ID:ACEZLY,项目名称:gim,代码行数:29,代码来源:ef_sock.cpp

示例5: libcfs_sock_accept

int
libcfs_sock_accept (cfs_socket_t **newsockp, cfs_socket_t *sock)
{
        cfs_socket_t   *newsock;
        int             rc;

        newsock = _MALLOC(sizeof(cfs_socket_t), M_TEMP, M_WAITOK|M_ZERO);
        if (!newsock) {
                CERROR("Can't allocate cfs_socket.\n");
                return -ENOMEM;
        }
        newsock->s_magic = CFS_SOCK_MAGIC;
        /*
         * thread will sleep in sock_accept by calling of msleep(), 
         * it can be interrupted because msleep() use PCATCH as argument.
         */
        rc = -sock_accept(C2B_SOCK(sock), NULL, 0, 0, 
                          libcfs_sock_upcall, newsock, &C2B_SOCK(newsock));
        if (rc) {
                if (C2B_SOCK(newsock) != NULL) 
                        sock_close(C2B_SOCK(newsock));
                FREE(newsock, M_TEMP);
                if ((sock->s_flags & CFS_SOCK_DOWN) != 0)
                        /* shutdown by libcfs_sock_abort_accept(), fake 
                         * error number for lnet_acceptor() */
                        rc = -EAGAIN;
                return rc;
        }
        *newsockp = newsock;
        return 0;
}
开发者ID:Lezval,项目名称:lustre,代码行数:31,代码来源:darwin-tcpip.c

示例6: node_del_data_event

void node_del_data_event(struct node *node)
{
	int ret;

	log_error("%s: del data event for node %d", __func__, node->id);
	ret = pthread_spin_trylock(&node->spinlock);
	if(ret != 0) {
		log_error("%s: del data event get lock failed", __func__);
		return;
	}

	if(node->data_event == NULL) {
		log_error("%s: null data_event for node %d, cancel", __func__, node->id);
		goto err;
	}

	shutdown(node->dfd, SHUT_RDWR);
	sock_close(node->dfd);
	node->dfd = -1;
	node->data_conn_state = NODE_DFD_DISCONNECTED;

	event_free(node->data_event);
	node->data_event = NULL;

	pthread_spin_unlock(&node->spinlock);

	clean_packet_queue(node->data_q);

	node_disconnect(node);

	return;

err:
	pthread_spin_unlock(&node->spinlock);
}
开发者ID:forthewatch,项目名称:xdm,代码行数:35,代码来源:node.c

示例7: Sock_close

int Sock_close(Sock *s)
{
    int res;

    if (!s)
        return -1;

    if(s->flags & IS_MULTICAST) {
        if (s->remote_host)
            mcast_leave(s->fd,(struct sockaddr *) &(s->remote_stg));
        else
            mcast_leave(s->fd,(struct sockaddr *) &(s->local_stg));
    }

#if HAVE_SSL
    if(s->flags & IS_SSL)
        sock_SSL_close(s->ssl);
#endif

    res = sock_close(s->fd);

    if (s->remote_host) free(s->remote_host);
    if (s->local_host) free(s->local_host);
    free(s);

    return res;
}
开发者ID:lidongliangfly,项目名称:Libnemesi-reborn,代码行数:27,代码来源:Sock_close.c

示例8: daemon_endcapture

int daemon_endcapture(pcap_t *fp, pthread_t *threaddata, char *errbuf)
{
struct rpcap_header header;
SOCKET sockctrl;

	if (threaddata)
	{
		pthread_cancel(*threaddata);
		threaddata= 0;
	}
	if (fp->rmt_sockdata)
	{
		sock_close(fp->rmt_sockdata, NULL, 0);
		fp->rmt_sockdata= 0;
	}

	sockctrl= fp->rmt_sockctrl;

	pcap_close(fp);
	fp= NULL;

	rpcap_createhdr( &header, RPCAP_MSG_ENDCAP_REPLY, 0, 0);

	if ( sock_send(sockctrl, (char *) &header, sizeof(struct rpcap_header), errbuf, PCAP_ERRBUF_SIZE) == -1)
		return -1;
	
	return 0;
}
开发者ID:OPEXGroup,项目名称:winpcap,代码行数:28,代码来源:daemon.c

示例9: client_disconnect_tcp

/*
 * Closes the TCP socket for the client (wrapper for sock_close()).
 */
void client_disconnect_tcp(client_t* c)
{
	if(c->connected) {
		sock_close(c->tcp_sock);
		c->connected = 0;
	}
}
开发者ID:PKRoma,项目名称:pwnat,代码行数:10,代码来源:client.c

示例10: sock_destroy

int sock_destroy(SOCKINFO *info, int ShutdownMethod)
{
	int ret = UPNP_E_SUCCESS;
	char errorBuffer[ERROR_BUFFER_LEN];

	if (info->socket != INVALID_SOCKET) {
#ifdef UPNP_ENABLE_OPEN_SSL
		if (info->ssl) {
			SSL_shutdown(info->ssl);
			SSL_free(info->ssl);
			info->ssl = NULL;
		}
#endif
		if (shutdown(info->socket, ShutdownMethod) == -1) {
			strerror_r(errno, errorBuffer, ERROR_BUFFER_LEN);
			UpnpPrintf(UPNP_INFO, HTTP, __FILE__, __LINE__,
				   "Error in shutdown: %s\n", errorBuffer);
		}
		if (sock_close(info->socket) == -1) {
			ret = UPNP_E_SOCKET_ERROR;
		}
		info->socket = INVALID_SOCKET;
	}

	return ret;
}
开发者ID:BelledonneCommunications,项目名称:libupnp,代码行数:26,代码来源:sock.c

示例11: irc_connect

int irc_connect(char *hostname, int port) {
    int fd;
    int nb;
    char *buff;
    char ip[IP_STR_LEN];

    /* resolve hostname to ip */
    nb = sock_dns(hostname, ip);
    if (!nb)
        return -1;

    /* get connected */
    fd = sock_connect(ip, port);
    if (fd == -1)
        return -1;

    /* register with server */
    buff = "NICK " IRC_NICKNAME "\r\nUSER " IRC_USERNAME " localhost server :"
           IRC_REALNAME "\r\n";
    nb = send(fd, buff, strlen(buff), 0);
    if (nb < 0) {
        sock_close(fd);
        return -1;
    }

    pthread_mutex_init(&lock, NULL);

    return fd; // persistent connection, return socket descriptor
}
开发者ID:IRCBotWars,项目名称:ircii,代码行数:29,代码来源:irc.c

示例12: session_close

/*!
 *\brief	child and parent cleanup (child closes first)
 *
 *\param	session Contains session information
 *
 *\return	 0 : success
 */
static gint session_close(Session *session)
{
	g_return_val_if_fail(session != NULL, -1);

	if (session->conn_id > 0) {
		sock_connect_async_cancel(session->conn_id);
		session->conn_id = 0;
		debug_print("session (%p): connection cancelled\n", session);
	}

	session_set_timeout(session, 0);

	if (session->io_tag > 0) {
		g_source_remove(session->io_tag);
		session->io_tag = 0;
	}

	if (session->sock) {
		sock_close(session->sock);
		session->sock = NULL;
		session->state = SESSION_DISCONNECTED;
		debug_print("session (%p): closed\n", session);
	}

	return 0;
}
开发者ID:moreorless,项目名称:claws-mail,代码行数:33,代码来源:session.c

示例13: main

int main(int argc, char** argv) {
	if (argc != 4) {
		fprintf(stderr, "%s\n", "required arguments: input file, IP address, port");
		exit(-1);
	}

	sock_desc sock = sock_tcp_init();
	sock_connect(sock, argv[2], atoi(argv[3]));

	FILE* input = fopen(argv[1], "r");
	char* buffer = malloc(BUFFER_SIZE);

	size_t size_read = 0;

	/* Send all the data from the file */
	while ((size_read = fread(buffer, sizeof(char), BUFFER_SIZE, input))) {
		sock_send(sock, size_read, buffer);
	}

	fprintf(stderr, LOG_PRE "%s\n", "file sent, closing socket");

	sock_close(sock);

	free(buffer);
	fclose(input);
}
开发者ID:ryanashcraft,项目名称:file-transfer,代码行数:26,代码来源:tcp_client.c

示例14: libcfs_sock_create

static int
libcfs_sock_create (cfs_socket_t **sockp, int *fatal,
                    __u32 local_ip, int local_port)
{
        struct sockaddr_in  locaddr;
        cfs_socket_t    *sock;
        int             option;
        int             optlen;
        int             rc;

        /* All errors are fatal except bind failure if the port is in use */
        *fatal = 1;

        sock = _MALLOC(sizeof(cfs_socket_t), M_TEMP, M_WAITOK|M_ZERO);
        if (!sock) {
                CERROR("Can't allocate cfs_socket.\n");
                return -ENOMEM;
        }
        *sockp = sock;
        sock->s_magic = CFS_SOCK_MAGIC;

        rc = -sock_socket(PF_INET, SOCK_STREAM, 0, 
                          libcfs_sock_upcall, sock, &C2B_SOCK(sock));
        if (rc != 0) 
                goto out;
        option = 1;
        optlen = sizeof(option);
        rc = -sock_setsockopt(C2B_SOCK(sock), SOL_SOCKET, 
                              SO_REUSEADDR, &option, optlen);
        if (rc != 0)
                goto out;

        /* can't specify a local port without a local IP */
        LASSERT (local_ip == 0 || local_port != 0);

        if (local_ip != 0 || local_port != 0) {
                bzero (&locaddr, sizeof (locaddr));
                locaddr.sin_len = sizeof(struct sockaddr_in);
                locaddr.sin_family = AF_INET;
                locaddr.sin_port = htons (local_port);
                locaddr.sin_addr.s_addr = (local_ip != 0) ? htonl(local_ip) : INADDR_ANY;
                rc = -sock_bind(C2B_SOCK(sock), (struct sockaddr *)&locaddr);
                if (rc == -EADDRINUSE) {
                        CDEBUG(D_NET, "Port %d already in use\n", local_port);
                        *fatal = 0;
                        goto out;
                }
                if (rc != 0) {
                        CERROR("Error trying to bind to port %d: %d\n",
                               local_port, rc);
                        goto out;
                }
        }
        return 0;
out:
        if (C2B_SOCK(sock) != NULL) 
                sock_close(C2B_SOCK(sock));
        FREE(sock, M_TEMP);
        return rc;
}
开发者ID:DCteam,项目名称:lustre,代码行数:60,代码来源:darwin-tcpip.c

示例15: lwip_socket

int lwip_socket(int domain, int type, int protocol) {
	int s, fd;

	// We only support basic internet protocols
	if (domain != AF_INET || protocol != 0 || (type != SOCK_STREAM && type != SOCK_DGRAM)) {
		errno = EPROTONOSUPPORT;
		return -1;
	}

	// Allocate a new socket for it
	s = sock_open();
	if (s < 0) {
		errno = ENFILE;
		return -1;
	}
	fds[s].type = type;

	// Make a VFS socket for it
	fd = fs_open_handle(&socketvfs, (void *)(s+1));
	if (fd < 0) {
		sock_close(s);
	}

	return fd;
}
开发者ID:foreverlikeyou9999,项目名称:kos-ports,代码行数:25,代码来源:sockets.c


注:本文中的sock_close函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。