[asterisk-users] utils.c: fwrite() returned error: Broken pipe how to solve it ???
A J Stiles
asterisk_list at earthshod.co.uk
Thu Oct 10 06:30:55 CDT 2013
On Thursday 10 October 2013, akhilesh chand wrote:
> Dear all,
>
> I want to make call through socket i have set code given below:
>
> #!/usr/bin/perl -w
>
> use IO::Socket::INET;
>
>
> sub asterisk_command ()
> {
> # my $command=$_[0];
> my
> $ami=IO::Socket::INET->new(PeerAddr=>'127.0.0.1',PeerPort=>5038,Proto=>'tcp
> ') or die "failed to connect to AMI!";
> print $ami "Action: Login\r\nUsername: lite\r\nSecret:
> 4003\r\n\r\nAction: Logoff\r\n\r\n";
> }
> &asterisk_command("Channel: DAHDI/27/7702009896\r\nExten: s\r\nContext:
> outbound\r\nCallerID: 20048645\r\nPriority: 1\r\nMaxRetries: 2\r\n");
>
> Whenever i execute that code i'm get following error
>
> [Oct 10 15:13:23] ERROR[856]: utils.c:1175 ast_careful_fwrite: fwrite()
> returned error: Broken pipe
> [Oct 10 15:13:23] ERROR[856]: utils.c:1175 ast_careful_fwrite: fwrite()
> returned error: Broken pipe
> [Oct 10 15:13:23] ERROR[856]: utils.c:1175 ast_careful_fwrite: fwrite()
> returned error: Broken pipe
> [Oct 10 15:13:23] ERROR[856]: utils.c:1175 ast_careful_fwrite: fwrite()
> returned error: Broken pipe
>
>
> asterisk verison :- 1.6.2.7
> CentOS release 5.3
> kernel version :- 2.6.18-128.el5
"Broken Pipe" is a bit misleading because it can refer to other modes of
connection besides pipes (although that certainly is the most common case
where you would see it). It just means something tried to write to a stream
that has already been closed.
In this case, AMI is trying to send back a response *after* you have already
closed the socket. To avoid the error, you need to see if there is any data
waiting to be read from the socket, and then read it. (Then, having gone to
the trouble of actually reading it, you may as well at least do a simple
regular expression match to ensure that what you were expecting to happen
actually happened.
Also, as Asterisk runs on Unix-like systems, you don't really need the
Microsoft-style \r\n line endings. Just an ordinary Unix-style \n on its own
will suffice. It even saves a few CPU cycles on the far end (not that you'll
ever actually notice from within an interpreted script).
--
AJS
Answers come *after* questions.
More information about the asterisk-users
mailing list