Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Cancel blocking socket operation in WinSock 2.0

Posted on 2001-08-14
8
Medium Priority
?
1,110 Views
Last Modified: 2008-02-01
For some reason, I use blocking socket in my program. Each of my working thread receive UDP data package from a certain port. During the application running, everyting is ok. But when I need to exit the program and tell all the working thread to shut down, the problem occurs. I can't use closesock(...) directly (from other thread), because if I do like this, it will also block (WSARecvFrom(...) is still waiting for the next package). After checking MSDN, I found a WinSock API WSACancelBlockingCall(), but it is only supported by WinSock 1.1. Now my temporary solution is terminate the waiting thread directly, then close the socket. But I feel it not so good, have you a better solution?
Thanks.
0
Comment
Question by:xutao
[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
8 Comments
 
LVL 4

Expert Comment

by:VincentLawlor
ID: 6411662
Don't use blocking socket calls use ansynchronous calls instead.

This way you can pass a shutdown handle as a parameter to each new thread you start.

Then in your code you can wait for the shutdownhandle to be signalled while waiting for socket events. If it is signalled do your clean up and allow the thread to exit gracefully rather than trying to terminate the thread.

Vin.

0
Manage your data center from practically anywhere

The KN8164V features HD resolution of 1920 x 1200, FIPS 140-2 with level 1 security standards and virtual media transmissions at twice the speed. Built for reliability, the KN series provides local console and remote over IP access, ensuring 24/7 availability to all servers.

 

Expert Comment

by:amp072397
ID: 6789692
xutao:

You have asked 21 questions here at EE, and you have only resolved 3 of them. Here is a list of your open questions. I will be posting this comment in all of them.

http://www.experts-exchange.com/jsp/qShow.jsp?ta=winntnet&qid=20154615
http://www.experts-exchange.com/jsp/qShow.jsp?ta=networkgen&qid=20154616
http://www.experts-exchange.com/jsp/qShow.jsp?ta=networkgen&qid=20160832
http://www.experts-exchange.com/jsp/qShow.jsp?ta=networkgen&qid=20168293
http://www.experts-exchange.com/jsp/qShow.jsp?ta=networkgen&qid=20171676
http://www.experts-exchange.com/jsp/qShow.jsp?ta=cplusprog&qid=11217097
http://www.experts-exchange.com/jsp/qShow.jsp?ta=cplusprog&qid=11872498
http://www.experts-exchange.com/jsp/qShow.jsp?ta=cplusprog&qid=20133253
http://www.experts-exchange.com/jsp/qShow.jsp?ta=cplusprog&qid=20133912
http://www.experts-exchange.com/jsp/qShow.jsp?ta=cplusprog&qid=20171681
http://www.experts-exchange.com/jsp/qShow.jsp?ta=cplusprog&qid=20171684
http://www.experts-exchange.com/jsp/qShow.jsp?ta=cplusprog&qid=20248551
http://www.experts-exchange.com/jsp/qShow.jsp?ta=cplusprog&qid=20248764
http://www.experts-exchange.com/jsp/qShow.jsp?ta=winprog&qid=20252102
http://www.experts-exchange.com/jsp/qShow.jsp?ta=winprog&qid=20254933
http://www.experts-exchange.com/jsp/qShow.jsp?ta=winprog&qid=20255719
http://www.experts-exchange.com/jsp/qShow.jsp?ta=winprog&qid=20258375

To assist you in your cleanup, I'm providing the following guidelines:

1.  Stay active in your questions and provide feedback whenever possible. Likewise, when feedback has not been provided by the experts, commenting again makes them receive an email notification, and they may provide you with further information. Experts have no other method of searching for questions in which they have commented, except manually.

2.  Award points by hitting the Accept Comment As Answer button located above and to the left of that expert's comment.

3.  When grading, be sure to read:
http://www.experts-exchange.com/jsp/cmtyQuestAnswer.jsp#3
to ensure that you understand the grading system here at EE. If you grade less than an A, you must explain why.

4.  Questions that were not helpful to you should be PAQ'd (stored in the database for their valuable content?even if not valuable to you) or deleted. To PAQ or delete a question, you must first post your intent in that question to make the experts aware. Then, if no experts object after three full days, you can post a zero-point question at community support to request deletion or PAQ. Please include the link(s) to the question(s).
CS:  http://www.experts-exchange.com/jsp/qList.jsp?ta=commspt
At that point, a moderator can refund your points and PAQ or delete the question for you. The delete button does not work.

5.  If you fail to respond to this cleanup request, I must report you to the Community Support Administrator for further action.

Our intent is to get the questions cleaned up, and not to embarrass or shame anyone. If you have any questions or need further assistance at all, feel free to ask me in this question or post a zero-point question at CS. We are very happy to help you in this task!


thanks!
amp
community support moderator

0
 
LVL 1

Author Comment

by:xutao
ID: 6791630
All your suggestions is not to use blocking socket. But what I want to know is how to make it in blocking mode.
0
 
LVL 5

Expert Comment

by:Netminder
ID: 6805771
Note sent today to Admin re: remaining open questions.

Netminder
Community Support Moderator
Experts Exchange
0
 
LVL 5

Expert Comment

by:Netminder
ID: 6834937
Points refunded and question closed.

Netminder
Community Support Moderator
Experts Exchange
0
 
LVL 5

Accepted Solution

by:
Netminder earned 0 total points
ID: 6834941
Admin notified of user neglect. Points refunded and question closed.

Netminder
Community Support Moderator
Experts Exchange
0

Featured Post

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

For many of us, the  holiday season kindles the natural urge to give back to our friends, family members and communities. While it's easy for friends to notice the impact of such deeds, understanding the contributions of businesses and enterprises i…
If you’re involved with your company’s wide area network (WAN), you’ve probably heard about SD-WANs. They’re the “boy wonder” of networking, ostensibly allowing companies to replace expensive MPLS lines with low-cost Internet access. But, are they …
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

688 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