2010-03-02 13:41 | Posted by Sunshow | Filed Under C, Network
调用libcurl下载,然后使用netstat查看发现有大量的TCP连接保持在CLOSE_WAIT状态 查看libcurl的文档说明,有这样一个选项: CURLOPT_FORBID_REUSE Pass a long. Set to 1 to make the next transfer explicitly close the connection when done. Normally, libcurl keeps all connections alive when done with one transfer in case a succeeding one follows that can re-use them. This option should be used with caution and only if you understand what it [...]
2009-11-14 16:34 | Posted by Sunshow | Filed Under C
相关RFC:http://curl.haxx.se/rfc/rfc2396.txt /* --------------------------------------------------------------------------- * Encode URL by converting special characters to %XX (where XX are hexadecimal digits) * Don't forget to free the return value. */ char *urlencode(const char *url) { #define COPY_TO_ENCODE_URL(c) \ if (outlen < pos) { \ outlen += 10; \ [...]
2009-07-16 13:41 | Posted by Sunshow | Filed Under C
有两种方法,一种是在accept的时候获取,一种是通过getpeername获取 #include <sys/socket.h> int accept(int socket, struct sockaddr *restrict address, socklen_t *restrict address_len); int getpeername(int socket, struct sockaddr *restrict address, socklen_t *restrict address_len); 两者区别主要在取IP的fd不一样,前者是在监听的fd,后者是在连接建立的fd struct sockaddr_in addr;socklen_t addr_len;int32_t listen_fd, sock_fd; /* create listening port */ addr_len = sizeof(addr); memset(&addr, 0, addr_len);sock_fd = accept(listen_fd, (struct sockaddr *)&addr, &addr_len);printf("%d\n", addr.sin_addr.s_addr); memset(&addr, 0, addr_len);getpeername(sock_fd, (struct sockaddr *)&addr, &addr_len);printf("%d\n", addr.sin_addr.s_addr); 当然这种长整型格式的IP不一定是我们想要的,可以通过inet_ntoa转换 [...]
Recent Comments