From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 96247 invoked by alias); 31 Jan 2018 08:15:49 -0000 Mailing-List: contact cygwin-help@cygwin.com; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner@cygwin.com Mail-Followup-To: cygwin@cygwin.com Received: (qmail 96069 invoked by uid 89); 31 Jan 2018 08:15:37 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-6.9 required=5.0 tests=BAYES_00,GIT_PATCH_2,TIME_LIMIT_EXCEEDED autolearn=unavailable version=3.3.2 spammy=UD:msg00194.html, msg00194html, msg00194.html, treating X-HELO: m0.truegem.net Received: from m0.truegem.net (HELO m0.truegem.net) (69.55.228.47) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 31 Jan 2018 08:15:23 +0000 Received: (from daemon@localhost) by m0.truegem.net (8.12.11/8.12.11) id w0V8FLHQ074725 for ; Wed, 31 Jan 2018 00:15:21 -0800 (PST) (envelope-from mark@maxrnd.com) Received: from 76-217-5-154.lightspeed.irvnca.sbcglobal.net(76.217.5.154), claiming to be "[192.168.1.100]" via SMTP by m0.truegem.net, id smtpdxUbYvQ; Wed Jan 31 00:15:17 2018 Subject: Re: RPC clnt_create() adress already in use To: cygwin@cygwin.com References: <59D90AF8D70E9740907BACDE2BCB520836E01220@RESW102.resdom01.local> From: Mark Geisert Message-ID: <812cb3b6-9d28-971c-45eb-38421d817ca4@maxrnd.com> Date: Wed, 31 Jan 2018 08:15:00 -0000 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:49.0) Gecko/20100101 Firefox/49.0 SeaMonkey/2.46 MIME-Version: 1.0 In-Reply-To: <59D90AF8D70E9740907BACDE2BCB520836E01220@RESW102.resdom01.local> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-SW-Source: 2018-01/txt/msg00290.txt.bz2 PAULUS, Raimund, TI-ABN wrote: > Hi Mark, > > in my email (https://sourceware.org/ml/cygwin/2017-12/msg00194.html) i described 2 approaches. I prefer nr 1. > Here the part of the source in bindresvport.c: > ------------------------------------------------------------------------------------------------------------------ > if (port == 0) { > port = (getpid() % NPORTS) + STARTPORT; > } > res = -1; > errno = EADDRINUSE; > > /* fix for bind() */ > port = 0; > again: > for (i = 0; i < nports; ++i) { > *portp = htons(port++); > if (port > endport) > port = startport; > res = bind(sd, sa, salen); > if (res >= 0 || errno != EADDRINUSE) > break; > } > if (i == nports && startport != LOWPORT) { > startport = LOWPORT; > endport = STARTPORT - 1; > nports = STARTPORT - LOWPORT; > port = LOWPORT + port % (STARTPORT - LOWPORT); > goto again; > } > mutex_unlock(&port_lock); > > return (res); > } > ------------------------------------------------------------------------------------------------------- > > This causes bind() to search an unused port. I use libtirpc with this fix since several weeks and it works for me. I don't know an other way (fixing Cygwin) to success. > The RPC-client on my pc is started every few minutes and has to connect to the RPC-server. Without the fix libtirpc is not usable and I have to use Cygwin 1.5.18 with the old librpc. [...] Hi Raimund, Thanks for attaching the complete source for your modified bindresvport.c. I had been treating your setting of port to 0 as a workaround rather than as a solution. My misunderstanding. We can't solve the issue that way because when bind() is called with a zeroed port number, it picks a random port number that's often outside the range of ports bindresvport() is supposed to return (i.e., a port between STARTPORT and ENDPORT). I thought of something similar to your idea but obeying the bindresvport() semantics. I add a static short value named 'usecount' to the function's local variables. Mid-function, I have this code to choose a port number: if (port == 0) { port = ((getpid() + usecount++) % NPORTS) + STARTPORT; } Can you try this with your testcase(s) and make sure it works for you? ..mark -- Problem reports: http://cygwin.com/problems.html FAQ: http://cygwin.com/faq/ Documentation: http://cygwin.com/docs.html Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple