🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.internet.socket
Article #5030

select() & ioctlsocket() problem

#5030
From: PaoloItaly
Date: Fri, 22 Oct 2004 11:20
37 lines
2084 bytes
Introduction:
- Server side
- succesfully connected with the client
- regular traffic of information
- the client close his socket
  -    ::shutdown(s->socket, SD_SEND);
        if (::closesocket(s->socket) == 0)
        {
          if (::WSACleanup() != 0)
            myWSAErrorCode(::WSAGetLastError());
        }
        else
            myWSAErrorCode(::WSAGetLastError());
- on the server side the reading loop (i've tested both method)
   1) avail = -1;
       bytes = ::ioctlsocket(sock, FIONREAD, &avail);
   2)  avail = -1;
        FD_ZERO(&read_fd);
        FD_SET(s->socket, &read_fd);
        if (::select(s->socket+1, &read_fd, NULL, NULL, NULL) !=
SOCKET_ERROR)
        {
          ret = ::ioctlsocket(s->socket, FIONREAD, &avail);
          if (ret == 0)
            return avail;
        }
        return -1;
Problem:
- select() return immediately (also if timeout parameter is NULL), returning
1 (no error)
  but this socket should be closed/invalid
- ioctlsocket() return 0 and set avail to 0
If i call recv() the function return SOCKET_ERROR (correct) but i've to read
data in a static buffer and i wish to allocate memory dinamically knowing
the exact size

Thanks in advance
Technical Details
Message-ID: <4178ed30@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!news.maxwell.syr.edu!news-out1.nntp.be!propagator2-sterling!in.nntp.be!caladan.arrakis.es!caladan.landsraad.net!newsgroups.borland.com!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Thread: 11508e,594e3ed9f24a168f,start
X-Google-Attributes: gid11508e,public
X-Google-Language: ENGLISH,ASCII-7-bit
From: "PaoloItaly" <paolot@FAKETHESPAMMERsirius-es.it>
Newsgroups: borland.public.cppbuilder.internet.socket
Subject: select() & ioctlsocket() problem
Date: Fri, 22 Oct 2004 13:20:55 +0200
Lines: 39
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1437
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1441
NNTP-Posting-Host: 82.105.234.125
Message-ID: <4178ed30@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1098444080 82.105.234.125 (22 Oct 2004 04:21:20 -0700)
Path: arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!news.maxwell.syr.edu!news-out1.nntp.be!propagator2-sterling!in.nntp.be!caladan.arrakis.es!caladan.landsraad.net!newsgroups.borland.com!not-for-mail