CAsyncSocket - Blocking vs. Non-blocking

In reading the MSDN library, there are a lot of statements 
like "A socket can be in 'blocking mode' or 'nonblocking 
mode'."

Specifically, in dealing with the function Send(...) what 
happens if the receiving end isn't ready to accept?  In 
some of the articles, it looks like it blocks, in others 
it looks like it ought to return with a WSAEWOULDBLOCK 
error.  The description of WSAEWOULDBLOCK says "The socket 
is marked as non-blocking and the requested operation 
would block."

So how do I "mark a socket as non-blocking"?

I thought that was the default.  It looks like my code is 
occaisionally blocking on the Send function.  I thought it 
should return WSAEWOULDBLOCK, and move on.

Any assistance would be appreciated.
0
david8009 (4)
12/3/2003 7:51:33 PM
vc.mfc 33608 articles. 0 followers. Follow

2 Replies
1880 Views

Similar Articles

[PageSpeed] 24

David wrote:

> In reading the MSDN library, there are a lot of statements 
> like "A socket can be in 'blocking mode' or 'nonblocking 
> mode'."
> 
> Specifically, in dealing with the function Send(...) what 
> happens if the receiving end isn't ready to accept?  In 
> some of the articles, it looks like it blocks, in others 
> it looks like it ought to return with a WSAEWOULDBLOCK 
> error.  The description of WSAEWOULDBLOCK says "The socket 
> is marked as non-blocking and the requested operation 
> would block."
> 
> So how do I "mark a socket as non-blocking"?
> 
> I thought that was the default.  It looks like my code is 
> occaisionally blocking on the Send function.  I thought it 
> should return WSAEWOULDBLOCK, and move on.
> 
> Any assistance would be appreciated.

CAsyncSocket creates a nonblocking socket.  Send does not block.  Note 
that Send does not directly return WSAEWOULDBLOCK.  It returns 
SOCKET_ERROR and then you have to call GetLastError to see the 
WSAEWOULDBLOCK code.

The blocking condition does not necessarily occur when the receiving end 
isn't ready.  Winsock buffers outgoing messages at the sending end.  It 
will continue accepting Send calls until its buffers are full.  If that 
happens then it will indicate WSAEWOULDBLOCK.

-- 
Scott McPhillips [VC++ MVP]

0
scottmcp1 (239)
12/4/2003 2:00:47 AM
Is CAsyncSocket::IOCtl what you are after?

"David" <david@blackdeck.com> wrote in message
news:01e801c3b9d6$da9f2ab0$a401280a@phx.gbl...
> In reading the MSDN library, there are a lot of statements
> like "A socket can be in 'blocking mode' or 'nonblocking
> mode'."
>
> Specifically, in dealing with the function Send(...) what
> happens if the receiving end isn't ready to accept?  In
> some of the articles, it looks like it blocks, in others
> it looks like it ought to return with a WSAEWOULDBLOCK
> error.  The description of WSAEWOULDBLOCK says "The socket
> is marked as non-blocking and the requested operation
> would block."
>
> So how do I "mark a socket as non-blocking"?
>
> I thought that was the default.  It looks like my code is
> occaisionally blocking on the Send function.  I thought it
> should return WSAEWOULDBLOCK, and move on.
>
> Any assistance would be appreciated.


0
number
12/4/2003 2:34:32 AM
Reply:

Similar Artilces:

MFC vs. WinForms
Anyone have any suggestion regarding using WinForms in .NET framework rather than MFC? Should one switch to WinForms for its ease of use and added functionality? What about the inconvenience of MSIL and CLR? ...

CAsyncSocket
My main thread creates a CAsyncSocket derived class and tries to connect to the server by calling the Connect method. Unfortunately, since CAsyncSocket is non-blocking, the OnConnect notification arrives as a message to the main window. But, I cannot continue processing until a successful connection has been established and I don't want to create a worker thread to initialize the socket. Is there any way I can process windows messages and wait until the OnConnect function returns with the connection status? "Rohit" <Rohit@discussions.microsoft.com> wrote in...

Checkbook Balance vs Cash Account Balance
We have a substantial difference between the number given for our checkbook balance and the cash account balance. We run a daily manual total, so we know that the cash account balance is correct. Where does the checkbook balance number pull from and why (all receipts, deposits, etc. are posted) would it be different from the cash account balance. All bank recs are current and in balance. Was it ever in balance? You will need to enetr an adjusting transaction into the Bank Rec. (Don't post to GL) module to fix it. "bjc" wrote: > We have a substantial difference bet...

Static Class vs Argument
Hello, I am working with IoC to inject a repository on a class. This is a simple example as I am starting with IoC so I am trying to have a simple example with XML files working. On HomeController I have the following: public class HomeController : Controller { private readonly IUserRepository _userRepository; public HomeController(IUserRepository userRepository) { this._userRepository = userRepository; } // HomeController public ActionResult Index() { ViewData["Email"] = _userRepository.FindByUsername("admin").Email; ...

Color vs Colorindex for series border
Running on Excel 2003, I am attempting to set the .border.color property for an x-y scatter series object using a long value that was generated by the RGB function. However, the colorindex property seems to override it. I can successfully change the marker colors, but the .border.color value reverts back to the one associated with the colorindex value. I don't want to change the palette because I have several charts in the workbook, each of which has its own color scheme based on the number of series in the chart. Anyone know why I can't just set the color property to an arbitra...

Benefits vs. Deductions
Hi, I am new to GP Payroll. We are converting from ADP to inhouse payroll using GP. I am in the process of setting everything up. Can I set up all deductions ie, health insurance, 401k, life, garnishments, etc under the deductions tab or must I set them under benefits? -- Thank you! MCallie: I strongly suggest you get training on GP Payroll if you don't have a very good local resource (either inhouse or through your GP reseller). GP Payroll is not very intuitive in its setup. You will for sure have to use both Deductions and Benefits and GP doesn't even handle garnishments prio...

CAsyncSocket::Receive and CAsyncSocket's threading...
Hi again, 1. Is CAsyncSocket::Receive a blocking function? 2. How is the IO Strategy for MFC's CAsyncSocket? 1 thread to do all stuff? Thanks again. pixelmana wrote: > Hi again, > 1. Is CAsyncSocket::Receive a blocking function? > 2. How is the IO Strategy for MFC's CAsyncSocket? 1 thread to do all stuff? > Thanks again. 1. No. "Async" means non-blocking. 2. CAsyncSocket sends you notifiction messages via the Windows message queue. These messages are just like button and mouse messages. CAsyncSocket turns them into calls to your derived class virtual fu...

Confusion in VS 2003 over declaring a new class....
We have an app that requires .net 1.1 to work, so are using VS 2003 for convenience. I'm most of the way through cleaning up the code that was originally created in VS 2008, so that it will not error on build. One particular statement has me a bit confused, as I cannot find any obvious examples to explain it. m_Results.PR = New Validator.Details currently complains that type Validator.Details is not defined, which is correct. I tried to add a new Details class to the Validator class, and declared several variables that are then used m_Results.PR.UPRN = getSelectedRowVal...

Charting Dow vs. Portfolio with dates
Given three columns - the date, say 30 to 90 days, the Dow Average over the same time, and a portfolio value, how can they appear in a sensible fashion? The Dows is about 10,000 and the portfolio is over 1,000,000, and the dates are 7/1/04 etc. I get two very distinct lines for the first two and gibberish for the dates. How to Handle? Please comment. If you have a heading in the date column, delete it Select a cell in the table, and click the Chart Wizard button Create a line chart from the data Right-click on the portfolio line Choose Format Selected Series On the Axis tab, select Secon...

International Versions of Money 2006 vs US Version
There is only one version of Money 2006 for Canadians (Microsoft Money 2006 Canadian Edition). There is no trial. 1. How does Money 2006 Canadian Edition compare to the Standard, Deluxe, Premium and Small Business editions available for US? 2. As a Canadian, what is the impact if I only use the US version? In microsoft.public.money, Brian wrote: >There is only one version of Money 2006 for Canadians (Microsoft Money 2006 >Canadian Edition). There is no trial. > >1. How does Money 2006 Canadian Edition compare to the Standard, Deluxe, >Premium and Small Business editi...

CAsyncSocket
I have been unable to figure out a way to detect that the server that my client is talking to has lost its physical connection to the network. I have a simple server and client for debugging this problem. The server just accepts a connection and sends out a line of text every second. The client just connects and reads the socket, displaying each line as it comes in To test this, I fire up the two apps on different machines and let them run for a bit. Then I unplug the server machine's network cable. The client does not receive any notification that something is wrong (no OnClose noti...

ByVal vs. ByRef 11-17-09
I guess I have fallen into the habit of generally passing values ByRef, unless I am certain that the method will never need to alter the value. Also I have never been quite sure what it means to pass a reference type ByVal. And I have never had a problem. Until this past weekend. This past weekend I was playing around with a TreeView representation of a directory and developed the code attached below. The code is very straightforward. A button click routine establishes the topmost node and then calls a recursive subroutine, Populate, to populate the rest of the tree. The ...

Understanding CAsyncSocket-- need perspective.
I've written several successful applications using CAsyncSocket, both server side and client side. I'm having trouble getting my mind around what exactly is going on in CAsyncSocket with a client side connection- and what the preferred method of connection is. My trouble is this: I've written a very small, q & d app which instantiates a casyncsocket on the stack, does a create() with no parameters and connects to a server (not under my control-- often a public site on say, an html port *80)). The connection always fails with WSAEWOULDBLOCK which I understand... in theory. ...

Indirect Function Doesn't like non-contiguous ranges
I was trying to use the indirect command to sum a named range of cells. If I enter the following in a cell then the formula works if the text in the cell refers to a contiguous range. If I change the range to be non- contiguous, it gives a #ref error in the cell. Cell contents =+SUM(INDIRECT(I66)) I66 has the string "rng1" which is a named range on the current worksheet. Does anyone have any idea of any work around? Please study CHOOSE function. Regards. I don't think you can use indirect for this =sum(rng1) will work -- Don Guillett SalesAid Software donaldb@281.com <...

Again with CAsyncSocket
I'm again with my attemp of implement a CAsyncSocket class to my project. I started from 0 again and have a class (MySocket:public CAsyncSocket) that has to manage the connections. The constructor creates the server socket: MySocket::MySocket() { //CAsyncSocket* pServer = new CAsyncSocket; this->numclients = 0; int nPort = 15000; int ret = this->Create( 15000 ); if( Listen()==FALSE ) { //ERROR } else { //NO ERROR } } This opens my server and starts listening connections: void MySocket::OnAccept(int nErrorCode) { CAsyncSocket* client = new CAsync...

WTL vs MFC : Same question as Yesterday
Does someone knows how to convert a CFormView to WTL. For now I have converted my CMainFrame like this: class CMainFrame : public CFrameWindowImpl<CMainFrame>, public CUpdateUI<CMainFrame>, public CAppWindow<CMainFrame>, public CFullScreenFrame<CMainFrame>, public CMessageFilter, public CIdleHandler { ... }; And now I would like to display some views inside. How can I do this ? If someone has some experience with this framework, I am all eyes. On Thu, 05 Apr 2007 14:46:22 +0200, mosfet wrote: > Does someone knows how to convert a CFormView to WTL. >...

getting players records vs. other players
Hi I am having trouble doing this. Here is what i have. I have a table that shows the date, winner, and loser. I then have 2 queries that counts the number of times Player A won vs. Player B, and then how many times Player A lost to Player B. I then combine thsoe 2 queries and it works fine provided Player A and Player B have at least 1 win and loss vs each other. If not, nothing shows up when i combine the queries So what I need is for it to show that Player A is 4-0 vs Player B and subsequently Player B is 0-4 vs Player A. Can someone help? example Player Team Won Oppon...

use of non inventory item for discounting
I have used non-inventory items for discounting purposes, but am not sure if i am doing it properly! I usually have all the items in one department called offers - but then i accumulate a big negative amount for that department, and am over-stating my sales for the other departments. I got around that by putting the item in the department that the discount related to, but that only works for item specific discounts... if i have a coupon worth -�10 and people can spend that on anything they want, then how would people usually deal with that? any feedback on this would be great! Ta! ...

Outlook 2003--How can I switch between unicode and non-unicode mode?
We are in the process of upgrading office 2002 to office 2003. We are running into the issue where we can't archive to .pst files created in outlook 2002. I understand the difference between the new unicode mode and non-unicode mode. I have found that an upgraded machine will run in non-unicode(older version of oultook) as long as outlook 2002 was set to sync. offline. But, if outlook 2002 was not set to sync offline, it will run in the new unicode mode once upgraded to 2003. We have several users already upgraded with several archive files already existing. It would be m...

CAsyncSocket: how do you send?
As part of the process of learning MFC I've written a simple dialog based app that should allow the user to connect to a server, exchange strings with it and disconnect- telnet, really. I come from a VB background and am familiar with using sockets in that environment. This is why I'm comfortable with the MFC dialog based approach to life.. Anyhow, I can connect OK and the server response is handled correctly and added to a list box, but I can't figure out for the life of me how to send anything. Please have a look at the code: class CTERMSocket : public CAsyncSocket { public: ...

is CAsyncSocket bidirectional?
Once I make a connection can I talk in both directions? Or must I create a separate connection with separate sockets for the return data? Thanks... Bill wrote: > Once I make a connection can I talk in both directions? Or must I create a > separate connection with separate sockets for the return data? > > Thanks... > > CAsyncSocket is bidirectional. Once a connection is established both sides may send and receive, in any order, independently. -- Scott McPhillips [VC++ MVP] I'm glad of that and thought it should be. But I did notice in my first CAsyncSock...

Stack vs. Heap
Is there a simple rule when to define objects on the heap and when to do it on the stack? Regards Dan Hi Dan, >Is there a simple rule when to define objects on the heap and when to do it >on the stack? See for yourself and decide: http://en.wikipedia.org/wiki/Heap_%28data_structure%29 http://en.wikipedia.org/wiki/Stack_(data_structure) Regards Kerem -- ----------------------- Beste Gr�sse / Best regards / Votre bien devoue Kerem G�mr�kc� Microsoft Live Space: http://kerem-g.spaces.live.com/ Latest Open-Source Projects: http://entwicklung.junetz.de ----------------------- ...

CAsyncSocket OnConnect()
Hi, I don't understand why the OnConnect() event is fired (at least in my program) even when there is no server to connect to at the IP adres where the client tries to connect to. Does the OnConnect always get called by the framework even when the connection isn't accepted by a server-socket ? Well, the system has to tell you that you didn't connect. OnConnect has an error code which should be checked to tell you the result of the attempt. > > Hi, > > I don't understand why the OnConnect() event is fired (at least in my > program) even when there is no ser...

Including non related text in a report
One of my reports is a letter, I have been asked to include a decision date on the letter. The database table does not hold this information and I was hoping that when a letter had to be printed, the report would prompt the inputter for the decision date and then include this on the report. I have thought about including a new field in the table, but the letters are few and far between. Can anyone provide me with help? Well, if you ever need to know a decision date of a past letter, then you really should store it in the table. Otherwise, it will only be on the printed l...

Using CAsyncSocket as a server.
I have used CAsyncSocket a bunch of times as a client. Now I want to use it as a server. My plan is make a new class using CAsyncSocket as a base. Then I will create one instance of my class and listen on the port I need. When someone connects to me I will start sending data using that instance of the class. Then immediately I will create a second instance of my CAsyncSocket based class and I will listen on the same port for someone else to connect. If someone connects I will start sending data using that instance. I will then create a third instance and listen again. Is this the general wa...