Solved

Windows Programming question

Posted on 1997-06-05
3
255 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

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

In this article, I will show how to use the Ribbon IDs Tool Window to assign the built-in Office icons to a ribbon button.  This tool will help us to find the OfficeImageId that corresponds to our desired built-in Office icon. The tool is part of…
As more and more people are shifting to the latest .Net frameworks, the windows presentation framework is gaining importance by the day. Many people are now turning to WPF controls to provide a rich user experience. I have been using WPF controls fo…
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…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…

734 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