Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner AT cygwin DOT com Mail-Followup-To: cygwin AT cygwin DOT com Delivered-To: mailing list cygwin AT cygwin DOT com From: "Peter Stephens" To: Subject: RE: recv and errno during a connection reset/closed by peer Date: Fri, 25 Mar 2005 17:18:40 -0500 Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit I boiled this down to nothing(see below). I must be missing something basic. I tried the suggestions made so far and it never gets to: printf(" >>> ERRNO %i\n", errno); I would expect that on a disconnect (I use putty in telnet or raw mode) it would return -1 whether it is doing MSG_PEEK or an actual retrieval. No luck. #include #include #include #include #include #include int main(int argc, char **argv) { int lfd=-1, afd=-1, temp=0; char buf[20]; lfd = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); if (-1 == lfd) printf("Error at socket(): %i\n", errno); // joris' suggestion #if 1 temp = 1; setsockopt(lfd, SOL_SOCKET, SO_KEEPALIVE,(char *)&temp, sizeof(temp)) ; #endif sockaddr_in svc; svc.sin_family = AF_INET; svc.sin_addr.s_addr = inet_addr("192.168.1.245"); svc.sin_port = htons(27015); if (-1 == bind(lfd, (struct sockaddr *) &svc, sizeof(svc))) printf("bind() failed.\n"); if (-1 == listen(lfd, 1 )) printf("Error listening on socket.\n"); printf("Waiting for client to connect...\n"); while( -1 == afd ){ afd = accept( lfd, NULL, NULL ); } printf("Client connected.\n"); int ret_val = 0; do{ ret_val = recv(afd, buf, 20, MSG_PEEK); if(0 > ret_val) printf(" >>> ERRNO %i\n", errno); else if(ret_val > 0){ ret_val = recv(afd, buf, 20, 0); buf[ret_val]='\0'; printf("(%i) > %s", ret_val, buf); } usleep(250); }while(ret_val>=0); return 0; } -- Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple Problem reports: http://cygwin.com/problems.html Documentation: http://cygwin.com/docs.html FAQ: http://cygwin.com/faq/