Return-Path: william@bourbon.usc.edu Delivery-Date: Thu Oct 9 06:59:39 2008 X-Spam-Checker-Version: SpamAssassin 3.2.3 (2007-08-08) on merlot.usc.edu X-Spam-Level: X-Spam-Status: No, score=-2.3 required=5.0 tests=AWL,BAYES_00 autolearn=ham version=3.2.3 Received: from bourbon.usc.edu (bourbon.usc.edu [128.125.9.75]) by merlot.usc.edu (8.14.1/8.14.1) with ESMTP id m99Dxdu7003393 for ; Thu, 9 Oct 2008 06:59:39 -0700 Received: from bourbon.usc.edu (localhost.localdomain [127.0.0.1]) by bourbon.usc.edu (8.14.2/8.14.1) with ESMTP id m99E6Afe022978 for ; Thu, 9 Oct 2008 07:06:10 -0700 Message-Id: <200810091406.m99E6Afe022978@bourbon.usc.edu> To: cs551@merlot.usc.edu Subject: Re: Connection establishment Date: Thu, 09 Oct 2008 07:06:10 -0700 From: Bill Cheng Someone wrote: > I went through the sequence when 3 nodes - X, Y and Z are started. I am > implementing the following sequence: > > Node X is started and it creates 2 child threads - say X1 and X2. > X1 is blocking on accept(). > X2 is trying to connect to Y and Z, inside a for loop that runs twice (or > minNeighbors number of times), and it sleeps for 30 seconds if no connection > formed. For a beacon node, it needs to connect to all other beacon ndoes. Remember, the beacon nodes form a fully connected mesh. The way you described it, it sounds like you just want to connect to another beacon node. By the way, MinNeighbors is only used by regular nodes. (The description mentioned the init_neighbor_list file and only a regular node uses the init_neighbor_list file.) Also, in my posting, for this example, node X would create one child thread to connect to Y and another child thread to connect to Z. Of course, you don't have to do it the way I mentioned. But I just want to make sure that there is no misunderstanding. > Same case for nodes Y and Z. > > I am getting a broken pipe error. > > Could this be because my thread (X2 or Y2 or Z2) are handling or forming 2 > separate connections with other 2 nodes using a for loop ? Most likely it's just a bug. > If yes, then does this mean that we need a new thread to handle every new > connection , and no thread can handle multiple connections at the same time > ? As I mentioned before, you can pretty much get anything reasonable to work. You can even use one thread to handle *all* the connections if you code it correctly! (But that would not be efficient. Also, threads are cheap, so you should take advantage of that if it makes your code clean and easier to debug.) You need to understand exactly what your code is doing. When it's not doing what it suppose to do, you need to debug, debug, and debug! -- Bill Cheng // bill.cheng@usc.edu