char *cwd; char buf[PATH_MAX+1]; if ((cwd = getcwd(buf,PATH_MAX+1)) == NULL) {perror("pwd");return(-1);} string filename(cwd); filename.append("/test.config"); ifstream aliasfile(filename.c_str(),ios::nocreate); if (!aliasfile.good()) return(-1); int sockfd; string t_ip,t_nename; while (aliasfile >;>;t_...
by mills - C/C++ - 2003-09-17 14:49:32 阅读(725) 回复(1)
在linux socket关闭连接的方法有两种分别是shutdown和close,首先看一下shutdown的定义 #include int shutdown(int sockfd,int how); how的方式有三种分别是 SHUT_RD(0):关闭sockfd上的读功能,此选项将不允许sockfd进行读操作。 SHUT_WR(1):关闭sockfd的写功能,此选项将不允许sockfd进行写操作。 SHUT_RDWR(2):关闭sockfd的读写功能。 成功则返回0,错误返回-1,错误码errno:EBADF表示sockfd不是一个有效描述符;ENOT...
由于受到syn,close_wait 的功能,我做了以下配置. sysctl -w net.ipv4.tcp_syncookies=1 sysctl -w net.ipv4.tcp_max_syn_backlog=3072 sysctl -w net.ipv4.tcp_synack_retries=1 sysctl -w net.ipv4.tcp_syn_retries=1 sysctl -w net.ipv4.conf.all.send_redirects=0 sysctl -w net.ipv4.conf.all.accept_redirects=0 sysctl -w net.ipv4.conf.all.forwarding=0 sysctl -w net.ipv4.icmp_echo_ignore_broadcasts=1 sysctl -w ...
linux上TCP的shutdown/close(备忘) linux的版本是kernel-2.6.21: 1,只要TCP栈的读缓冲里还有未读取(read)数据,则调用close时会直接向对端发送RST。 2,shutdown与socket描述符没有关系,即使调用shutdown(fd, SHUT_RDWR)也不会关闭fd,最终还需close(fd)。 3,可以认为shutdown(fd, SHUT_RD)是空操作,因为shutdown后还可以继续从该socket读取数据,这点也许还[color="#cc0000"]需要进一步证实。 4,...
/***************************************** * open and close file descriptors * ********************************************/ #include #include #include #include #include #include int main(void) { int fd; char path[]="hello"; if((fd=open(path,O_CREAT|O_TRUNC|O_WRONLY,0644) 本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u/21905/showart_220097.html
I have a TXT file with contents named test.txt as follow: This is a test 444444 333333 good by! I defined a ifstream variable named inFile and intialized with a string "test.txt", and I defined string outString and an ofstream variable named outFile with "output.txt" for initializing.I used the statements for coping the content of file test.txt into file output.txt as follow: inFile >;>; outStri...
我使用ifstream 方式来实现文件读写并通过socket发送。现在请问两个问题: 1、socket的send和receive函数,一次发送和接收多少个字节最为合理,效率最高? 2、我如何定位当前文件所要读的位置,就是类似于fseed()的功能,能够分多次把文件读完,每次读一部分并发送。 比较急,在线等待,谢谢
Dear all: I am going to read a file "data.dat", its content is: [Code] 5 0 2 3 5 2 4 2 4 2 4 3 100 1 3 4 2 3 2 2 3 4 2 200 2 3 5 3 5 4 4 2 4 3 300 2 3 5 2 4 2 4 2 4 2 400 2 3 5 2 3 2 4 2 4 2 500 1 3 5 2 4 2 4 2 3 2 [/code] I want to sepearate the data into three part. The first one is [code] N=5; [/code] The second one is [code] key=[0 2 3 5 2 4 2 4 2 4 ...