Przemyslaw,

I'm writing a ftpd server, when a transfer is happening and, for example, I
have an error writing data to disk I have to stop incoming data and notify
client that the transfer has been aborted.

Looking around I've seen that one solution is to shutdown() the socket and
receive pending data while sending on the control socket a code telling the
client I've aborted the transfer.

hb_InetClose() does an automatic shutdown, I saw it, but I think that a
following hb_InetRecv() on a closed socket will give me an error.

Maybe I can just don't bother, close the socket and send the abort code, I
admit that I've not made tests since adding hb_InetShutdown() seemed to me so
easy .)

BTW, I don't know why xharbout has a shutdown() just before a close.

Thanks.

Maurilio.

Przemysław Czerpak wrote:
> On Tue, 16 Feb 2010, Maurilio Longo wrote:
> 
> Hi Maurilio,
> 
>> I'd like to add this code to hbinet.c
>> HB_FUNC( HB_INETSHUTDOWN )
>> {
>>    PHB_SOCKET_STRUCT socket = HB_PARSOCKET( 1 );
>>    if( socket )
>>    {
>>       if( socket->sd != HB_NO_SOCKET )
>>       {
>>          hb_retni( hb_socketShutdown( socket->sd, HB_SOCKET_SHUT_RDWR ) );
>> #if 0
>> #ifdef HB_INET_LINUX_INTERRUPT
>>          kill( 0, HB_INET_LINUX_INTERRUPT );
>> #endif
>> #endif
>>       }
>>       else
>>          hb_retni( -1 );
>>    }
>>    else
>>       hb_inetErrRT();
>> }
>> to be able to shutdown a socket before closing it,
> 
> Have you noticed that hb_socketShutdown() is called automatically
> in hb_inetClose() and when socket is closed automatically by destructor?
> Why you need to call it explicitly?
> 
> It's redundant. All hb_inet*() sockets are 
> 
>> I've commented out #ifdef
>> HB_INET_LINUX_INTERRUPT which I don't know what it really does.
> 
> HB_INET_LINUX_INTERRUPT is a macro which enables code using signals
> to interrupt socket operation. Giancarlo used it in original xHarbour
> socket implementation and as I can see it's still there. In this
> context it's used to wake up other threads waiting on the same socket.
> I disabled it in default Harbour builds because our hb_fs* API is still
> not safe for interrupting by asynchronous signals so it may cause
> problems on kernels which do not resume interrupted disk operations
> (POSIX compatible behavior).
> HB_INET_LINUX_INTERRUPT is enough guard to disable this code and you do
> not have to add #if 0 yet.
> 
>> Do you think it's ok to commit it like this?
> 
> Just let me know if you why you need it.
> I have nothing against adding HB_INETSHUTDOWN() function but it
> should support for 2-nd parameter so user can use it to selectively
> close only read or write streams.
> 
>> And, by the way, after this call, a call to hb_InetClose() would shutdown
>> socket again, which I don't think would create problems, but I don't have a
>> full vision of sockets in all supported platforms.
> 
> Personally I'm very interested why this explicit call to shutdown() just
> before close[socket]() was added to xHarbour and what was the intentional
> behavior of this code. I replicated it in HB_INET*() functions in Harbour
> to keep it compatible.
> 
> best regards,
> Przemek
> _______________________________________________
> Harbour mailing list (attachment size limit: 40KB)
> Harbour@harbour-project.org
> http://lists.harbour-project.org/mailman/listinfo/harbour
> 

-- 
 __________
|  |  | |__| Maurilio Longo
|_|_|_|____| farmaconsult s.r.l.


_______________________________________________
Harbour mailing list (attachment size limit: 40KB)
Harbour@harbour-project.org
http://lists.harbour-project.org/mailman/listinfo/harbour

Reply via email to