From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 17098 invoked by alias); 20 Oct 2003 15:25:45 -0000 Mailing-List: contact ecos-discuss-help@sources.redhat.com; run by ezmlm Precedence: bulk List-Subscribe: List-Archive: List-Post: List-Help: , Sender: ecos-discuss-owner@sources.redhat.com Received: (qmail 17059 invoked from network); 20 Oct 2003 15:25:44 -0000 Received: from unknown (HELO web14204.mail.yahoo.com) (216.136.172.146) by sources.redhat.com with SMTP; 20 Oct 2003 15:25:44 -0000 Message-ID: <20031020152543.93964.qmail@web14204.mail.yahoo.com> Received: from [208.248.82.254] by web14204.mail.yahoo.com via HTTP; Mon, 20 Oct 2003 08:25:43 PDT Date: Mon, 20 Oct 2003 15:25:00 -0000 From: Matt Jerdonek To: Gary Thomas Cc: Discussion eCos In-Reply-To: <1066501848.20516.662.camel@hermes> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Subject: Re: [ECOS] TCP close(...) action X-SW-Source: 2003-10/txt/msg00345.txt.bz2 Gary, I can't send the actual code, so I put together this program. I verified this program exhibits the same behavior as I initially described. In addition, I put some comments in the code regarding the f_ucount. This is a member of the cyg_file structure which is associated with each socket. Once the f_ucount reaches 0, the FIN will be sent on the ethernet. #include #include #include #include #include #include #include #include #define STACK_SIZE 0x4000 unsigned char Stack[STACK_SIZE]; pthread_t ThreadHandle; int sockfd; void RecvThread(void); int main(void) { pthread_attr_t ThreadAttrib; init_all_network_interfaces(); // Create thread to make TCP connection pthread_attr_init(&ThreadAttrib); pthread_attr_setstackaddr(&ThreadAttrib, &Stack[STACK_SIZE]); pthread_attr_setstacksize(&ThreadAttrib, STACK_SIZE); pthread_create(&ThreadHandle, &ThreadAttrib, (void *)RecvThread, (void *)NULL); // Give the thread plenty of time to connect sleep(15); // Workaround ... // ... call cyg_thread_release() here ... // ... on the RecvThread // Close the socket printf("Closing socket\n"); close(sockfd); // The close will decrement the f_ucount ... // ... from 2 to 1, but the FIN will not ... // ... be sent until the recv is released. // ... See function fp_ucount_dec( ) ... // ... in io/fileio/ver/src/fd.cxx sleep(10); return(0); } void RecvThread(void) { // Create socket and connect to host sockfd = socket(AF_INET, SOCK_STREAM, 0); if (sockfd > 0) { struct sockaddr RmtHost; struct sockaddr_in *pRmtHost = (struct sockaddr_in *)&RmtHost; // At this point the cyg_file .. // ... structure that describes ... // ... the sockfd ... // ... as a f_ucount = 1 // Setup connect memset( &RmtHost, 0, sizeof(struct sockaddr) ); pRmtHost->sin_len = sizeof( struct sockaddr_in ); pRmtHost->sin_family = AF_INET; pRmtHost->sin_port = htons(4096); pRmtHost->sin_addr.s_addr = htonl(0xc8640196); // Connected to the host if (connect(sockfd, &RmtHost, sizeof(struct sockaddr)) >= 0) { unsigned char RxBuffer[100]; printf("Socket connected\n"); // Will block indefinitely ... // ... since no data will ... // ... be received recv(sockfd, &RxBuffer[0], 1, 0); // Inside the recv, ... // ... the f_ucount is now 2 printf("Recv woke\n"); } } } --- Gary Thomas wrote: > On Sat, 2003-10-18 at 12:24, Matt Jerdonek wrote: > > Hi Folks, > > > > I have a simple program with two threads that send > / > > recv from a single TCP socket. One thread blocks > on a > > recv call while the other thread sends data on the > > same socket. > > > > I put a close call in the send thread. The > expected > > behavior was for the recv thread to wake (with 0 > bytes > > of data) and a FIN to be sent on the ethernet. > The > > actual behavior was that the recv thread never > woke > > and the FIN was not sent. (Is this intended or a > > bug?). I found the soclose function would not be > > invoked because the recv was still using the file > > handle. Once the recv released the file handle, > the > > FIN flowed on the ethernet. > > > > I worked around this issue by calling > > cyg_thread_release from my application, which woke > up > > the recv thread. But I wonder if there is better > > solution? Could (or should) the close call be > made to > > wake up blocked threads? If so, any suggestions? > > > > How did you create this socket? How did you set up > the send and receive threads? Maybe a code snippet > would > help us understand your problem. > > -- > Gary Thomas > MLB Associates > > > -- > Before posting, please read the FAQ: > http://sources.redhat.com/fom/ecos > and search the list archive: > http://sources.redhat.com/ml/ecos-discuss > __________________________________ Do you Yahoo!? The New Yahoo! Shopping - with improved product search http://shopping.yahoo.com -- Before posting, please read the FAQ: http://sources.redhat.com/fom/ecos and search the list archive: http://sources.redhat.com/ml/ecos-discuss