Solved

Windows Programming question

Posted on 1997-06-05
3
252 Views
Last Modified: 2013-12-03
Overview:

I am developing a multi-threaded app for NT using MFC and VC++ 5.0 that creates multiple simultaneous CSocket connections (both UDP and TCP) in their own "worker" threads. After 60+ TCP connection failures my app, and my machine, "freeze". If only a few connection errors occur, the app runs fine.



My present theory is that the failed connections leave sockets in open or indeterminate states even after I explicity call CSocket::Close. Is this a known problem? Is there a way to force CSocket or the OS to free these resources?



Details:

The app is spawning mutilple simultaneous threads to deliver email via SMTP. Each thread creates one UDP socket to do a MX record lookup from a DNS server and then a second TCP thread to connect to the SMTP server. The UDP socket is closed and its CSocket object destroyed before the TCP socket is created. A connection failure results in an exception being thrown which ultimately calls CSocket::Close. After a connection failure the same CSocket object may then be re-used to attempt a connection to a different server. In general however the CSocket objects are not re-used unless an error occurs as each thread creates its own CSocket objects each time it's spawned.



The connection failures happen at random throughout the sending process, however the number of connection failures before the app freezes remains relatively constant. I have set a max limit of 30 simultaneous threads, and the app tends to average about 15-20 threads actually running at any given time. These threads are running with a priority of "above normal." Memory and CPU usage do not seem to be a factor as the app runs fine if no connection errors occur.



I have created my own socket class that inherits from CSocket that uses a timer to timeout the UDP receives on the DNS lookups. Other than this I'm using CSocket without modification.



Typical connection failures are:

10060 - Connection Timeout

10065 - No Route

10051 - Net Unreachable

10022 - Invalid Arg. - Seems to refer to unresolvable domain names

10048 - Address in use - Very rare, maybe 1 in 500000 connections.



Any help would be much appreciated.



Thanks-

Frank Vernon
0
Comment
Question by:frankv060597
  • 2
3 Comments
 
LVL 2

Expert Comment

by:amartin030297
ID: 1397871
Just my $.02--
  I suspect that the winsock.dll may have threads running
at normal priority level rather than above.  So with a
large number of threads running at a higher priority, you
may be starving the winsock threads.  I recommend you try
creating the threads at normal priority... then IF you want,
dynamically change your whole processes priority class (which
is scarry also, but worth a try).
  -- Aaron

0
 

Author Comment

by:frankv060597
ID: 1397872
Aaron-



Thanks so much for you quick and insightfull response. This was definately part of my trouble. The thread priority issue was compounded by a few things in CSocket::Recieve() but I now have it all working.



In testing various combinations, I found that setting the worker thread priority to "below normal" actually increased throughput since it ensures that a maximum number of threads are running at any given time. Since I am heavily bound by network latency this turned out to help a bit.



Thanks again-

Frank Vernon



BTW- This is a very very cool site. I hope I can help someone myself someday.
0
 
LVL 2

Accepted Solution

by:
amartin030297 earned 0 total points
ID: 1397873
I'm glad that helped you... I had only put it as a comment
rather than as an answer since I was unsure.. HOWEVER...
since you have the problem solved, would you mind sending
the points my way?? (Since you can't get 'em back anyway)
-- Aaron
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This article surveys and compares options for encoding and decoding base64 data.  It includes source code in C++ as well as examples of how to use standard Windows API functions for these tasks. We'll look at the algorithms — how encoding and decodi…
With most software applications trying to cater to multiple user needs nowadays, the focus is to make them as configurable as possible. For e.g., when creating Silverlight applications which will connect to WCF services, the service end point usuall…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question