<br><br><div class="gmail_quote">On Sun, Oct 21, 2012 at 3:35 AM, Glyph <span dir="ltr">&lt;<a href="mailto:glyph@twistedmatrix.com" target="_blank">glyph@twistedmatrix.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
I&#39;m top-posting just for consistency in this thread, but in the future please comment inline with trimming :).  It&#39;s easier to follow for future readers; if they find a post stand-alone in some web archive, the question will come before the answer.<br>

<br>
Anyhow; Mike, you&#39;re definitely closer to the answer; a callLater is unnecessary, the callback should be called on demand.  But, given that a queue of write operations is just that - a queue - we don&#39;t need a Deferred for every write; the callback to the write operation can just pick up the next queued item.<br>

<span class="HOEnZb"><font color="#888888"><br>
-g<br>
</font></span><div class="im HOEnZb"><br>
On Oct 20, 2012, at 9:07 AM, Mike Winter &lt;<a href="mailto:miwinter@cisco.com">miwinter@cisco.com</a>&gt; wrote:<br>
<br>
&gt; This looks like the kind of thing that could involve using Deferred as part of solution. Instead of callLater(0.8,doWrite), design the mechanism to wire up event-source to fire the deferred and make doWrite be the callback.<br>

&gt;<br>
&gt; On Oct 20, 2012, at 8:29:10AM, gelin yan wrote:<br>
&gt;<br>
&gt;&gt; Hi All<br>
&gt;&gt;<br>
&gt;&gt;  A few months ago, I reported a bug about IOCP. Last night I spent several hours on its implementation and finally found out a possible solution for that.<br>
&gt;&gt;<br>
&gt;&gt;  when sending some small chunks data continuously, the buffer will pile them up and send to IOCP; however there is a SEND_LIMIT (128K) that means only 128K will be handled. Now the problem is when we try to trigger the next writing, IOCP will raise ERROR_IO_PENDING immediately and then connection Lost.<br>

&gt;&gt;<br>
&gt;&gt;  So I got a idea: if the size of data is larger than SEND_LIMIT, we can wait a little bit time for the next writing instead of do it immediately.<br>
&gt;&gt;<br>
&gt;&gt; in twisted\internet\iocpreactor\abstract.py there is a method<br>
&gt;&gt;<br>
&gt;&gt; def _cbWrite(self, rc, bytes, evt):<br>
&gt;&gt;        if self._handleWrite(rc, bytes, evt):<br>
&gt;&gt;            self.doWrite()<br>
&gt;&gt;<br>
&gt;&gt; now I modified a bit,<br>
&gt;&gt;<br>
&gt;&gt; def _cbWrite(self, rc, bytes, evt):<br>
&gt;&gt;        if self._handleWrite(rc, bytes, evt):<br>
&gt;&gt;            if len(evt.buff) &lt; self.SEND_LIMIT:<br>
&gt;&gt;                self.doWrite()<br>
&gt;&gt;            else:<br>
&gt;&gt;                self.reactor.callLater(0.8,self.doWrite)<br>
&gt;&gt;<br>
&gt;&gt;<br>
&gt;&gt;<br>
&gt;&gt; 0.8 is a silly trial but I have no idea what is the right number for this place. After this modification, previous problematic scripts can pass.<br>
&gt;&gt;<br>
&gt;&gt; Maybe the better solution is to find a way to poll the complete port status when read/write will be recovered from IO PENDING. Simply wait a little is risky.<br>
&gt;&gt;<br>
&gt;&gt; Regards<br>
<br>
<br>
<br>
</div><div class="HOEnZb"><div class="h5">_______________________________________________<br>
Twisted-Python mailing list<br>
<a href="mailto:Twisted-Python@twistedmatrix.com">Twisted-Python@twistedmatrix.com</a><br>
<a href="http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python" target="_blank">http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python</a><br>
</div></div></blockquote></div><br><div><br></div><div><font size="4">Hi All</font></div><div><font size="4"><br></font></div><div><font size="4">   Thanks for reply. According to MSDN (link here: <a href="http://msdn.microsoft.com/en-us/library/windows/desktop/ms683209(v=vs.85).aspx">http://msdn.microsoft.com/en-us/library/windows/desktop/ms683209(v=vs.85).aspx</a>)</font></div>
<div><br></div><div>&quot;<font face="arial, helvetica, sans-serif"><span style="color:rgb(42,42,42);font-size:12px;line-height:18px">A pending operation is indicated when the function that started the operation returns </span><strong style="color:rgb(42,42,42);font-size:12px;line-height:18px">FALSE</strong><span style="color:rgb(42,42,42);font-size:12px;line-height:18px">, and the </span><a href="http://msdn.microsoft.com/en-us/library/windows/desktop/ms679360(v=vs.85).aspx" style="text-decoration:none;color:rgb(3,105,122);font-size:12px;line-height:18px"><strong>GetLastError</strong></a><span style="color:rgb(42,42,42);font-size:12px;line-height:18px"> function returns </span><strong style="color:rgb(42,42,42);font-size:12px;line-height:18px">ERROR_IO_PENDING</strong><span style="color:rgb(42,42,42);font-size:12px;line-height:18px">. When an I/O operation is pending, the function that started the operation resets the </span><strong style="color:rgb(42,42,42);font-size:12px;line-height:18px">hEvent</strong><span style="color:rgb(42,42,42);font-size:12px;line-height:18px"> member of the </span><strong style="color:rgb(42,42,42);font-size:12px;line-height:18px">OVERLAPPED</strong><span style="color:rgb(42,42,42);font-size:12px;line-height:18px"> structure to the nonsignaled state. Then when the pending operation has been completed, the system sets the event object to the signaled state</span></font><span style="color:rgb(42,42,42);font-family:&#39;Segoe UI&#39;,&#39;Lucida Grande&#39;,Verdana,Arial,Helvetica,sans-serif;font-size:12px;line-height:18px">.&quot;</span></div>
<div><span style="color:rgb(42,42,42);font-family:&#39;Segoe UI&#39;,&#39;Lucida Grande&#39;,Verdana,Arial,Helvetica,sans-serif;font-size:12px;line-height:18px"><br></span></div><div><span style="color:rgb(42,42,42);font-family:&#39;Segoe UI&#39;,&#39;Lucida Grande&#39;,Verdana,Arial,Helvetica,sans-serif;font-size:12px;line-height:18px">  </span><span style="color:rgb(42,42,42);font-family:&#39;Segoe UI&#39;,&#39;Lucida Grande&#39;,Verdana,Arial,Helvetica,sans-serif;line-height:18px"><font size="4">If we can know when event object is in the signaled state we definitely can use a queue directly. Any idea?</font></span></div>
<div><span style="color:rgb(42,42,42);font-family:&#39;Segoe UI&#39;,&#39;Lucida Grande&#39;,Verdana,Arial,Helvetica,sans-serif;line-height:18px"><font size="4"><br></font></span></div><div><span style="color:rgb(42,42,42);font-family:&#39;Segoe UI&#39;,&#39;Lucida Grande&#39;,Verdana,Arial,Helvetica,sans-serif;line-height:18px"><font size="4">Regards</font></span></div>
<div><span style="color:rgb(42,42,42);font-family:&#39;Segoe UI&#39;,&#39;Lucida Grande&#39;,Verdana,Arial,Helvetica,sans-serif;line-height:18px"><font size="4"><br></font></span></div><div><span style="color:rgb(42,42,42);font-family:&#39;Segoe UI&#39;,&#39;Lucida Grande&#39;,Verdana,Arial,Helvetica,sans-serif;line-height:18px"><font size="4">gelin yan</font></span></div>
<div><span style="color:rgb(42,42,42);font-family:&#39;Segoe UI&#39;,&#39;Lucida Grande&#39;,Verdana,Arial,Helvetica,sans-serif;font-size:12px;line-height:18px"><br></span></div><div><span style="color:rgb(42,42,42);font-family:&#39;Segoe UI&#39;,&#39;Lucida Grande&#39;,Verdana,Arial,Helvetica,sans-serif;font-size:12px;line-height:18px">  </span></div>
<div><span style="color:rgb(42,42,42);font-family:&#39;Segoe UI&#39;,&#39;Lucida Grande&#39;,Verdana,Arial,Helvetica,sans-serif;font-size:12px;line-height:18px"><br></span></div><div><span style="color:rgb(42,42,42);font-family:&#39;Segoe UI&#39;,&#39;Lucida Grande&#39;,Verdana,Arial,Helvetica,sans-serif;font-size:12px;line-height:18px"><br>
</span></div>