Click here to Skip to main content
15,901,982 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: C++ & MFC -> Listbox Question Pin
Wes Aday7-Apr-04 12:09
professionalWes Aday7-Apr-04 12:09 
GeneralRe: C++ & MFC -> Listbox Question Pin
Qualvis7-Apr-04 22:08
Qualvis7-Apr-04 22:08 
GeneralRe: C++ & MFC -> Listbox Question Pin
Qualvis7-Apr-04 22:32
Qualvis7-Apr-04 22:32 
GeneralRe: C++ & MFC -> Listbox Question Pin
Wes Aday8-Apr-04 7:08
professionalWes Aday8-Apr-04 7:08 
Generalsetting page orientation Pin
kzyczynski7-Apr-04 5:31
kzyczynski7-Apr-04 5:31 
GeneralRe: setting page orientation Pin
Roger Allen7-Apr-04 5:38
Roger Allen7-Apr-04 5:38 
GeneralRe: setting page orientation Pin
kzyczynski7-Apr-04 10:20
kzyczynski7-Apr-04 10:20 
GeneralSocket listen backlog woes Pin
Rob Caldecott7-Apr-04 5:15
Rob Caldecott7-Apr-04 5:15 
OK, I think I might know what the answer to this is going to be, put I'll post my problem anyway, as you never know, there may be a simpler solution...

I have a service app that listems for incoming socket connections using good old Berkeley style socket code - I have code that creates the socket to listen on and then a thread that uses "select" to wait for the connections, spawning a new thread per-connection to handle the data, e.g.:

<br />
for ( ; ; )<br />
{<br />
    ...<br />
    fd_set read;<br />
    FD_ZERO(&read);<br />
    FD_SET(m_hSocket, &read);<br />
    int nResult = ::select(-1, &read, NULL, NULL, &tv);<br />
    if (nResult == 1)<br />
    {<br />
        // Accept the connection<br />
        SOCKET s = ::accept(read.fd_array[i], NULL, NULL);<br />
       // Create a thread to process the incoming connection<br />
      AfxBeginThread(...);<br />
    }<br />
}<br />


The problem is that if I hammer the app using a test program that creates lots of simultaneous connections to the server (using a separate thread for each all started at once), before long some of these connections will fail with WSAECONNREFUSED. This seems to be because creating the thread to handle the accepted socket in the code above is expensive in terms of CPU and the incoming connections piling up whilst I am doing this are causing the backlog (5 sockets?) to be exceeded.

I *think* the answer will be to use IO completion ports but this is going to be a big job. The threads I create to process each socket are short-lived, and I know IOCP can ensure fewer are needed but will it also help with this backlog problem or is there another more generic way to handle this? At some point in the distant future I may want to port the code to Linux (yikes!) so I wanted to avoif anything MS specific.

Comments?


The Rob Blog
GeneralRe: Socket listen backlog woes Pin
beetung7-Apr-04 8:14
beetung7-Apr-04 8:14 
GeneralRe: Socket listen backlog woes Pin
Rob Caldecott7-Apr-04 9:53
Rob Caldecott7-Apr-04 9:53 
GeneralRe: Socket listen backlog woes Pin
Johnny ²7-Apr-04 8:56
Johnny ²7-Apr-04 8:56 
GeneralRe: Socket listen backlog woes Pin
Rob Caldecott7-Apr-04 9:52
Rob Caldecott7-Apr-04 9:52 
GeneralRe: Socket listen backlog woes Pin
Paul Ranson8-Apr-04 3:12
Paul Ranson8-Apr-04 3:12 
QuestionIs transparent window needed? Pin
conrad Braam7-Apr-04 4:49
conrad Braam7-Apr-04 4:49 
GeneralCreating a GUI for a C program Pin
EstC7-Apr-04 4:36
EstC7-Apr-04 4:36 
GeneralRe: Creating a GUI for a C program Pin
Roman Nurik7-Apr-04 4:55
Roman Nurik7-Apr-04 4:55 
GeneralRe: Creating a GUI for a C program Pin
EstC7-Apr-04 5:03
EstC7-Apr-04 5:03 
GeneralRe: Creating a GUI for a C program Pin
CPAVG7-Apr-04 5:24
CPAVG7-Apr-04 5:24 
GeneralRe: Creating a GUI for a C program Pin
EstC7-Apr-04 5:29
EstC7-Apr-04 5:29 
GeneralRe: Creating a GUI for a C program Pin
David Crow7-Apr-04 5:41
David Crow7-Apr-04 5:41 
GeneralRe: Creating a GUI for a C program Pin
Prakash Nadar7-Apr-04 6:17
Prakash Nadar7-Apr-04 6:17 
GeneralRe: Creating a GUI for a C program Pin
EstC7-Apr-04 5:11
EstC7-Apr-04 5:11 
GeneralRe: Creating a GUI for a C program Pin
Ravi Bhavnani7-Apr-04 6:04
professionalRavi Bhavnani7-Apr-04 6:04 
Generalchar to BSTR Pin
roadragedave7-Apr-04 4:14
roadragedave7-Apr-04 4:14 
GeneralRe: char to BSTR Pin
Diddy7-Apr-04 4:43
Diddy7-Apr-04 4:43 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.