标签:
void cloud_sum(int sockfd) { ssize_t n; char buf[MAXLINE]; long a = 0, b = 0; again: while ( (n = read(sockfd, buf, MAXLINE)) > 0){ if (sscanf(buf, "%ld %ld", &a, &b) > 0) snprintf(buf, sizeof(buf), "%ld\n", a + b); else snprintf(buf, sizeof(buf), "input error\n"); n = strlen(buf); write(sockfd, buf, n); fputs(buf, stdout); bzero(buf, sizeof(char) * MAXLINE); } if (n < 0 && EINTR == errno) goto again; else if (n < 0) cout<<"read error!"<<endl; else if (0 == n) cout<<"EOF"<<endl;
}
标签:
原文地址:http://www.cnblogs.com/LarryGen/p/5428270.html