Home > Archive > Unix Programming > December 2004 > send() was hold when sending message with Bolcking mode
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
send() was hold when sending message with Bolcking mode
|
|
| Ethan Yu 2004-12-09, 4:02 pm |
| Hi,
In my case, send() function is used for sending server message by client and
the socket's mode is Blocking. When the server broke down, the client still
sent message because it didn't know the server was down. After a while, the
send() was hold and couldn't be recovered.
When the socket uses blocking mode, how to recover the blocked send()?
Thanks,
Ethan
| |
| Barry Margolin 2004-12-09, 8:57 pm |
| In article <cp9oft$n0s$1@news.yaako.com>, "Ethan Yu" <ycy_76@163.net>
wrote:
> Hi,
>
> In my case, send() function is used for sending server message by client and
> the socket's mode is Blocking. When the server broke down, the client still
> sent message because it didn't know the server was down. After a while, the
> send() was hold and couldn't be recovered.
> When the socket uses blocking mode, how to recover the blocked send()?
You can use alarm() to send a signal if send() blocks for too long. Or
use select() to check whether the socket is writable.
--
Barry Margolin, barmar@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
| |
| Ethan Yu 2004-12-13, 4:08 pm |
| Barry, thanks! The client run based single thread, so the client will still
be blocked if I use alarm() to send a signal.
And in ethereal package, no signal was found when server broke down, I think
we can't get state of this connect.
"Barry Margolin" <barmar@alum.mit.edu> 写入消息新闻:barmar-2FB128.19305409122004@comcast.dca.giganews.com...
> In article <cp9oft$n0s$1@news.yaako.com>, "Ethan Yu" <ycy_76@163.net>
> wrote:
>
>
> You can use alarm() to send a signal if send() blocks for too long. Or
> use select() to check whether the socket is writable.
>
> --
> Barry Margolin, barmar@alum.mit.edu
> Arlington, MA
> *** PLEASE post questions in newsgroups, not directly to me ***
| |
| Barry Margolin 2004-12-13, 9:01 pm |
| In article <cpkbt3$99e$1@news.yaako.com>, "Ethan Yu" <ycy_76@163.net>
wrote:
> Barry, thanks! The client run based single thread, so the client will still
> be blocked if I use alarm() to send a signal.
If the SIGALRM handler performs a longjmp(), the send() will be exited
as a result. Or you can disable system call restarting for SIGALRM, so
send() will return -1 with errno set to EINTR.
> And in ethereal package, no signal was found when server broke down, I think
> we can't get state of this connect.
Signals are not something that shows up on the network, they're internal
to the Unix process. Did you mean "no message was sent when server
broke down"? That's true. This is why you have to use some kind of
timeout in the application.
[color=darkred]
> "Barry Margolin" <barmar@alum.mit.edu>
> 写入消息新闻:barmar-2FB128.19305409122004@comcast.dca.giganews.com...
--
Barry Margolin, barmar@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
| |
| Ethan Yu 2004-12-15, 3:58 pm |
| Barry, thanks! The client run based single thread, so the client will still
be blocked if I use alarm() to send a signal.
And in ethereal package, no signal was found when server broke down, I think
we can't get state of this connect.
"Barry Margolin" <barmar@alum.mit.edu> 写入消息新闻:barmar-2FB128.19305409122004@comcast.dca.giganews.com...
> In article <cp9oft$n0s$1@news.yaako.com>, "Ethan Yu" <ycy_76@163.net>
> wrote:
>
>
> You can use alarm() to send a signal if send() blocks for too long. Or
> use select() to check whether the socket is writable.
>
> --
> Barry Margolin, barmar@alum.mit.edu
> Arlington, MA
> *** PLEASE post questions in newsgroups, not directly to me ***
| |
| Ethan Yu 2004-12-15, 3:58 pm |
|
"Barry Margolin" <barmar@alum.mit.edu> 写入消息新闻:barmar-E8FCD0.19414113122004@comcast.dca.giganews.com...
> In article <cpkbt3$99e$1@news.yaako.com>, "Ethan Yu" <ycy_76@163.net>
> wrote:
>
>
> If the SIGALRM handler performs a longjmp(), the send() will be exited
> as a result. Or you can disable system call restarting for SIGALRM, so
> send() will return -1 with errno set to EINTR.
Good idea! I'll try this solution.
Barry, thanks for your help!
>
> Signals are not something that shows up on the network, they're internal
> to the Unix process. Did you mean "no message was sent when server
> broke down"? That's true. This is why you have to use some kind of
> timeout in the application.
Yes, the server broke down due to platform restarting, then no FIN, RESET or
other messages
were deliveried.
>
> --
> Barry Margolin, barmar@alum.mit.edu
> Arlington, MA
> *** PLEASE post questions in newsgroups, not directly to me ***
|
|
|
|
|