• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C++ sock_close函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: sock_open

int sock_open(const char* host, int port)
{
	char szPort[10];
	struct addrinfo hints;
	struct addrinfo *servinfo, *p;
	int rv, sockfd = -1;

	sprintf(szPort, "%d", port);
	memset( &hints, 0, sizeof(struct addrinfo));
	hints.ai_family = AF_UNSPEC;
	hints.ai_socktype = SOCK_STREAM;
	hints.ai_protocol = IPPROTO_TCP;

	rv = getaddrinfo(host, szPort, &hints, &servinfo);
	if (rv != 0) {
		printf("getaddrinfo failed: %d\n", rv);
		return -1;
	}

	for (p = servinfo; p !=NULL; p = p->ai_next) {
		if ((sockfd = socket(p->ai_family, p->ai_socktype, p->ai_protocol)) > 0) {
			if (connect(sockfd, p->ai_addr, p->ai_addrlen) == 0) {
				break;
			} else {
				sock_close(sockfd);
				sockfd = -1;
			}
		}
	}
	freeaddrinfo(servinfo);

	return sockfd;
}
开发者ID:bumptech,项目名称:riack,代码行数:33,代码来源:riack_sock.c


示例17: try_connect_HELO

int try_connect_HELO(const char *hostname)
{
    char dbg_hostname[BIG_BUF];
    char dbg_version[BIG_BUF];
    char buf[BIG_BUF];
    char testme[BIG_BUF];

    /* Try the HELO protocal */
    if(my_socket != -1)
        sock_close(my_socket);

    if (sock_open(get_string("mailserver"), get_number("smtp-socket", 25), &my_socket))
        return 0;

    if (sock_readline(my_socket, buf, sizeof(buf)) == 0)
        return 0;

    if(!sscanf(buf,"220 %s %s", &dbg_hostname[0], &dbg_version[0]))
        return 0;
    log_printf(9, "Connected: %s (%s)\n", dbg_hostname, dbg_version);

    sock_printf(my_socket, "HELO %s\r\n", hostname);
    if(sock_readline(my_socket, buf, sizeof(buf)) == 0)
        return 0;
    if(!sscanf(buf, "250 %s", testme))
        return 0;
    return 1;
}
开发者ID:icyfork,项目名称:ecartis,代码行数:28,代码来源:smtp.c


示例18: riack_connect

int riack_connect(struct RIACK_CLIENT *client, const char* host, int port,
		struct RIACK_CONNECTION_OPTIONS* options)
{
	client->sockfd = sock_open(host, port);
	if (client->sockfd > 0) {
		if (client->host && host != client->host) {
			RFREE(client, client->host);
		}
		if (host != client->host) {
			client->host = (char*)RMALLOC(client, strlen(host)+1);
			strcpy(client->host, host);
		}
		client->port = port;
		if (options) {
			client->options = *options;
			if (!sock_set_timeouts(client->sockfd, options->recv_timeout_ms, options->send_timeout_ms)) {
				sock_close(client->sockfd);
				client->sockfd = -1;
				// TODO set last error
			}
		}
		return RIACK_SUCCESS;
	}
	return RIACK_ERROR_COMMUNICATION;
}
开发者ID:fumpierrez,项目名称:riack,代码行数:25,代码来源:riack.c


示例19: libcfs_sock_listen

int
libcfs_sock_listen (cfs_socket_t **sockp,
                   __u32 local_ip, int local_port, int backlog)
{
        cfs_socket_t    *sock;
        int             fatal;
        int             rc;

        rc = libcfs_sock_create(&sock, &fatal, local_ip, local_port);
        if (rc != 0)  {
                if (!fatal)
                        CERROR("Can't create socket: port %d already in use\n",
                                local_port);
                return rc;

        }
        rc = -sock_listen(C2B_SOCK(sock), backlog);
        if (rc == 0) {
                *sockp = sock;
                return 0;
        }

        if (C2B_SOCK(sock) != NULL) 
                sock_close(C2B_SOCK(sock));
        FREE(sock, M_TEMP);
        return rc;
}
开发者ID:DCteam,项目名称:lustre,代码行数:27,代码来源:darwin-tcpip.c


示例20: sock_connect_wto_bind

sock_t sock_connect_wto_bind (const char *hostname, int port, const char *bnd, int timeout)
{
    sock_t sock;

    sock = sock_open (AF_INET, SOCK_STREAM, 0);
    if (sock == SOCK_ERROR)
        return SOCK_ERROR;

    if (bnd)
    {
        struct sockaddr_in sa;

        memset(&sa, 0, sizeof(sa));
        sa.sin_family = AF_INET;

        if (inet_aton (bnd, &sa.sin_addr) == 0 ||
                bind (sock, (struct sockaddr *)&sa, sizeof(sa)) < 0)
        {
            sock_close (sock);
            return SOCK_ERROR;
        }
    }

    if (timeout)
    {
        sock_set_blocking (sock, 0);
        if (sock_try_connection (sock, hostname, port) < 0)
        {
            int ret = sock_connected (sock, timeout);
            if (ret <= 0)
            {
                sock_close (sock);
                return SOCK_ERROR;
            }
        }
        sock_set_blocking(sock, 1);
    }
    else
    {
        if (sock_try_connection (sock, hostname, port) < 0)
        {
            sock_close (sock);
            sock = SOCK_ERROR;
        }
    }
    return sock;
}
开发者ID:jorisvandesande,项目名称:icecast-kh,代码行数:47,代码来源:sock.c



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ sock_errno函数代码示例发布时间:2022-05-30
下一篇:
C++ sock_alloc_send_skb函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap