{{Quickfixn}} Where is the best placed to catch socket exceptions?

Stan stan.quickfixn at gmail.com
Mon Sep 10 21:28:06 PDT 2012


The C++ version seems to have used send() which returns -1 on failure. The
C# equivalent throws an exception instead. Perhaps it makes sense to catch
the exception early.

Attached is a patch. Please kindly consider it for inclusion.


On Tue, Sep 11, 2012 at 1:19 AM, Stan <stan.quickfixn at gmail.com> wrote:

> Looking through the source code, I note that BUF_SIZE for
> SocketInitiatorThread.cs and SocketReader.cs are 512 bytes and 4096 bytes.
> I wonder if these are too small for some TCP applications with low
> bandwidth and high latency? (That could be the cause of my SocketException.)
>
> Perhaps there should be some configuration file option for these buffer
> sizes? And also TcpClient.SendBufferSize and TcpClient.ReceiveBufferSize.
>
> Regards,
> S
>
> On Tue, Sep 11, 2012 at 12:48 AM, Stan <stan.quickfixn at gmail.com> wrote:
>
>> Hi all, I am porting a server program originally written with QuickFIX
>> C++ .Net wrapper to QuickFIX/n. It worked well for several hours until it
>> suddenly crashed with this SocketException (extracted from Event Viewer):
>>
>> Framework Version: v4.0.30319
>> Description: The process was terminated due to an unhandled exception.
>> Exception Info: System.Net.Sockets.SocketException
>> Stack:
>>    at System.Net.Sockets.Socket.Send(Byte[], Int32, Int32,
>> System.Net.Sockets.SocketFlags)
>>    at QuickFix.ClientHandlerThread.Send(System.String)
>>    at QuickFix.Session.Send(System.String)
>>    at QuickFix.Session.SendRaw(QuickFix.Message, Int32)
>>    at QuickFix.Session.Send(QuickFix.Message)
>>    at QuickFix.Session.SendToTarget(QuickFix.Message, QuickFix.SessionID)
>>    at MyProg.SendData(System.Collections.Generic.List`1<NoMDEntriesGroup>)
>>    ...
>>
>> I am guessing the SocketException could be due to various reasons, e.g.
>> TCP buffer full, client disconnected, etc. That happens on a busy network.
>>
>> What I would like to know though is how I should handle this issue. Do I
>> need to put a try-catch around ALL calls to Session.SendToTarget? I've
>> never did this in the server program when using the .Net wrapper and have
>> assumed that SendToTarget would always return gracefully with false if it
>> failed to send. What is the recommended best practice? Advice and
>> suggestions are most appreciated.
>>
>> Regards,
>> S
>>
>> _______________________________________________
>> Quickfixn mailing list
>> Quickfixn at lists.quickfixn.com
>> http://lists.quickfixn.com/listinfo.cgi/quickfixn-quickfixn.com
>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.quickfixn.com/pipermail/quickfixn-quickfixn.com/attachments/20120911/e8cfa953/attachment-0002.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: CatchSocketException.patch
Type: application/octet-stream
Size: 1943 bytes
Desc: not available
URL: <http://lists.quickfixn.com/pipermail/quickfixn-quickfixn.com/attachments/20120911/e8cfa953/attachment-0002.obj>


More information about the Quickfixn mailing list