From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-0.9 required=5.0 tests=BAYES_00,FORGED_GMAIL_RCVD, FREEMAIL_FROM autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: a07f3367d7,cac8222034605353,start X-Google-Attributes: gida07f3367d7,public,usenet X-Google-NewGroupId: yes X-Google-Language: ENGLISH,ASCII Path: g2news1.google.com!postnews.google.com!j4g2000yqe.googlegroups.com!not-for-mail From: mockturtle Newsgroups: comp.lang.ada Subject: GNAT.Sockets, Create_Selector and error 10055 on Windows Date: Sat, 5 Dec 2009 01:22:14 -0800 (PST) Organization: http://groups.google.com Message-ID: NNTP-Posting-Host: 93.37.247.1 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Trace: posting.google.com 1260004934 24086 127.0.0.1 (5 Dec 2009 09:22:14 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Sat, 5 Dec 2009 09:22:14 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: j4g2000yqe.googlegroups.com; posting-host=93.37.247.1; posting-account=9fwclgkAAAD6oQ5usUYhee1l39geVY99 User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.1.6) Gecko/20070208 Mandriva/2.0.0.6-12mdv2008.0 (2008.0) Firefox/2.0.0.6,gzip(gfe),gzip(gfe) Xref: g2news1.google.com comp.lang.ada:8313 Date: 2009-12-05T01:22:14-08:00 List-Id: Dear all, I would like to share with you a problem we recently experienced with Create_Selector on Windows and that drove us (especially my student) crazy. Maybe some of you could be interested in it. My student is developing a program in Ada (did you guess? :) that communicates over the network. The code includes a procedure like procedure read_with_timeout (socket : socket_type; result : out data_packet; timeout : duration) is selector : selector_type; -- other variables begin create_selector(selector); -- Other code that adds socket to the read -- set and waits for data or timeout close_selector(selector); end read_with_timeout; The procedure above is called inside a loop. If the read operation was succesfull, the packet is processed, otherwise the code does something else. On Linux everything is fine and the code runs without any problem. On Windows the code runs for approximately 2 minutes then it dies with "10055 No buffer space available". My student fought with this problem for a couple of days, then he decided to give a look to the TCP/IP traffic and he discovered that there were many (hundreds?) TCP connection to localhost in TIME-WAIT state. He got the intuition that the problem could be on the select and he moved the definition and initialization of Selector outside the procedure, in the package body. This solved the problem, so we deduced that the TCP connections were opened by the Create_Selector. However, the song "Perch=E9 lo fai?" (Why do you do it?) by Marco Masini came irresistibly to our minds... By looking into the GNAT sources I discovered the reason (correct me if I am wrong): in order to allow for the "abort" of check_selector, GNAT create two connected file descriptor and add the read-side to the list of descriptors waited for. On Linux the two FDs are created with pipe() and no problem arise, but on Windows it falls back to a portable version that uses TCP connections. Those connections remain in the TIME-WAIT state and consume resources. Note that Close_Selector was called at the end of the procedure (actually, the TIME-WAIT state is a symptom that the connection was closed). As I said above, we were able to make the code work with the slightly inelegant (but innocuous [in our specific case]) solution of moving the selector outside the procedure. However I decided to signal this issue because it could be of some help to someone else (and maybe it could be read by someone of the GNAT people).