* ax25d and STDIN
@ 2002-09-27 5:08 Ben Gelb
2002-09-27 7:52 ` Tomi Manninen OH2BNS
0 siblings, 1 reply; 7+ messages in thread
From: Ben Gelb @ 2002-09-27 5:08 UTC (permalink / raw)
To: linux-hams
I am trying to write a simple scripts in PHP to run with ax25d. It will
be used to collect information from aid stations at the upcoming Marine
Corps Marathon in Washington, D.C.
I didn't want to get into network programming if it isn't necessary. And
I would prefer to use an uncompiled language, like php or perl, so that
I can make changes quickly if necessary.
To output data I am using fopen("php://stdout", "w"); and to read data I
am using fopen("php://stdin", "r"); The writing data part works fine,
but whenever I attempt to read in data from stdin, ax25d hangs up.
I have noticed in C++ I get this same problem when I attempt to use
scanf to read in. However, if I use cin instead, it works fine.
Does anybody know why this occurs and what I might do about it?
Thanks Very Much!
73 de Ben, KF4KJQ
^ permalink raw reply [flat|nested] 7+ messages in thread* Re: ax25d and STDIN
2002-09-27 5:08 ax25d and STDIN Ben Gelb
@ 2002-09-27 7:52 ` Tomi Manninen OH2BNS
2002-09-27 11:34 ` Ben Gelb
0 siblings, 1 reply; 7+ messages in thread
From: Tomi Manninen OH2BNS @ 2002-09-27 7:52 UTC (permalink / raw)
To: Ben Gelb; +Cc: linux-hams
On 27 Sep 2002, Ben Gelb wrote:
> To output data I am using fopen("php://stdout", "w"); and to read data I
> am using fopen("php://stdin", "r"); The writing data part works fine,
> but whenever I attempt to read in data from stdin, ax25d hangs up.
What do you mean by ax25d hanging up?
After spawning a program ax25d doesn't actively participate in the
communication between the program and the connectee. To spawn a program it
simply does a fork() followed by an exec(). The programs stdin/out/err are
redirected to point at the incoming connection socket (dup2()) before the
exec call.
What you may be seeing is the side effect of AX.25 sockets being
SOCK_SEQPACKET sockets. This means you always have to read a full packet
when reading. If you read less than a full packet worth of data, the rest
of the packet is thrown away. In practise you have no way of knowing how
big packet there might be waiting in the kernel buffers so you will have
to do a read() with a buffer "big enough"...
The standard IO libraries do various amounts of buffering if you use stdio
functions to read so that might explain why something works and something
else does not.
Then again you might be having some completely another problem with your
program... :)
--
Tomi Manninen Internet: oh2bns@sral.fi
OH2BNS AX.25: oh2bns@oh2rbi.fin.eu
KP20ME04 Amprnet: oh2bns@oh2rbi.ampr.org
^ permalink raw reply [flat|nested] 7+ messages in thread* Re: ax25d and STDIN
2002-09-27 7:52 ` Tomi Manninen OH2BNS
@ 2002-09-27 11:34 ` Ben Gelb
2002-09-27 23:09 ` Tomi Manninen
0 siblings, 1 reply; 7+ messages in thread
From: Ben Gelb @ 2002-09-27 11:34 UTC (permalink / raw)
To: tpm; +Cc: linux-hams
When I say 'hangs up' I mean that the user is disconnected from the ax25
link. I should have been more specific. For some reason, the link dies.
I was using fgets to read data. I tried using fread with length of 1024,
2048, and 10000. It was no different.
I doubt the problem is in my program. It basically asks the user for a
line of input, which it them spits back out again. It is simply a test
program. It works fine on the console (yes, I remembered to change the
return character to '\r' when I run it with ax25d).
I am starting to sense there may not be an easy solution to this
problem.
Thanks for answering so quickly!
73 Ben
On Fri, 2002-09-27 at 03:52, Tomi Manninen OH2BNS wrote:
> On 27 Sep 2002, Ben Gelb wrote:
>
> > To output data I am using fopen("php://stdout", "w"); and to read data I
> > am using fopen("php://stdin", "r"); The writing data part works fine,
> > but whenever I attempt to read in data from stdin, ax25d hangs up.
>
> What do you mean by ax25d hanging up?
>
> After spawning a program ax25d doesn't actively participate in the
> communication between the program and the connectee. To spawn a program it
> simply does a fork() followed by an exec(). The programs stdin/out/err are
> redirected to point at the incoming connection socket (dup2()) before the
> exec call.
>
> What you may be seeing is the side effect of AX.25 sockets being
> SOCK_SEQPACKET sockets. This means you always have to read a full packet
> when reading. If you read less than a full packet worth of data, the rest
> of the packet is thrown away. In practise you have no way of knowing how
> big packet there might be waiting in the kernel buffers so you will have
> to do a read() with a buffer "big enough"...
>
> The standard IO libraries do various amounts of buffering if you use stdio
> functions to read so that might explain why something works and something
> else does not.
>
> Then again you might be having some completely another problem with your
> program... :)
>
> --
> Tomi Manninen Internet: oh2bns@sral.fi
> OH2BNS AX.25: oh2bns@oh2rbi.fin.eu
> KP20ME04 Amprnet: oh2bns@oh2rbi.ampr.org
>
> -
> To unsubscribe from this list: send the line "unsubscribe linux-hams" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply [flat|nested] 7+ messages in thread* Re: ax25d and STDIN
2002-09-27 11:34 ` Ben Gelb
@ 2002-09-27 23:09 ` Tomi Manninen
2002-09-28 5:19 ` Ben Gelb
0 siblings, 1 reply; 7+ messages in thread
From: Tomi Manninen @ 2002-09-27 23:09 UTC (permalink / raw)
To: Ben Gelb; +Cc: linux-hams
Hi again Ben,
> When I say 'hangs up' I mean that the user is disconnected from the ax25
> link. I should have been more specific. For some reason, the link dies.
> I was using fgets to read data. I tried using fread with length of 1024,
> 2048, and 10000. It was no different.
Ok, so it is probably not the SEQPACKET problem either. However I really
can't think of any other explanation than a problem with your program.
As I said when someone connects to your system, ax25d accept()s the
connection, then fork()s. The parent process (ax25d) closes the socket
belonging to the incoming connection thereby completely detaching itself
from it. Ax25d then continues as if it never knew about that connection.
The child process copies the incoming connecting socket to it's
stdin/out/err and then exec()s your program. After that your program has
full control over the connection. Only your program can close the
connection.
Well, there is another possibility and that is that the kernel closes the
connection for some reason. I think some misconfiguration of the kernel
ax25 support could cause that to happen.
Anyway my first guess still is that there is something wrong with your
program. Are you absolutely 100% sure that ax25d manages to start it?
Could the read fail for some other reason? Have you tried logging exactly
what fails? I recommend making your program log each and every possible
error situation somewhere, maybe the system log.
--
Tomi Manninen Internet: oh2bns@sral.fi
OH2BNS AX.25: oh2bns@oh2rbi.fin.eu
KP20ME04 Amprnet: oh2bns@oh2rbi.ampr.org
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: ax25d and STDIN
2002-09-27 23:09 ` Tomi Manninen
@ 2002-09-28 5:19 ` Ben Gelb
2002-09-29 18:26 ` Tomi Manninen
0 siblings, 1 reply; 7+ messages in thread
From: Ben Gelb @ 2002-09-28 5:19 UTC (permalink / raw)
To: tpm; +Cc: linux-hams
Thanks for helping me with this.
I have made some progress.
I have replaced the line where I originally tried to use fgets, with
this wierd hacky solution:
while(1) {
$c = fread($in, 1);
if($c == $RETURN_CHAR) break;
$in_string.= $c;
}
The program works as intended now.
Using fread with a large length doesn't work, because EOF is never found
in stdin. So it just keeps waiting for the number of bytes specified.
I don't really understand why this works with the SEQPACKET
consideration. I am definitely not getting the whole packet at once,
yet, as I said, it does work.
Does this make any sense to you?
Thanks for you help!
73 Ben
On Fri, 2002-09-27 at 19:09, Tomi Manninen wrote:
> Hi again Ben,
>
> > When I say 'hangs up' I mean that the user is disconnected from the ax25
> > link. I should have been more specific. For some reason, the link dies.
> > I was using fgets to read data. I tried using fread with length of 1024,
> > 2048, and 10000. It was no different.
>
> Ok, so it is probably not the SEQPACKET problem either. However I really
> can't think of any other explanation than a problem with your program.
>
> As I said when someone connects to your system, ax25d accept()s the
> connection, then fork()s. The parent process (ax25d) closes the socket
> belonging to the incoming connection thereby completely detaching itself
> from it. Ax25d then continues as if it never knew about that connection.
>
> The child process copies the incoming connecting socket to it's
> stdin/out/err and then exec()s your program. After that your program has
> full control over the connection. Only your program can close the
> connection.
>
> Well, there is another possibility and that is that the kernel closes the
> connection for some reason. I think some misconfiguration of the kernel
> ax25 support could cause that to happen.
>
> Anyway my first guess still is that there is something wrong with your
> program. Are you absolutely 100% sure that ax25d manages to start it?
> Could the read fail for some other reason? Have you tried logging exactly
> what fails? I recommend making your program log each and every possible
> error situation somewhere, maybe the system log.
>
> --
> Tomi Manninen Internet: oh2bns@sral.fi
> OH2BNS AX.25: oh2bns@oh2rbi.fin.eu
> KP20ME04 Amprnet: oh2bns@oh2rbi.ampr.org
>
> -
> To unsubscribe from this list: send the line "unsubscribe linux-hams" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply [flat|nested] 7+ messages in thread* Re: ax25d and STDIN
2002-09-28 5:19 ` Ben Gelb
@ 2002-09-29 18:26 ` Tomi Manninen
2002-09-29 22:14 ` Ben Gelb
0 siblings, 1 reply; 7+ messages in thread
From: Tomi Manninen @ 2002-09-29 18:26 UTC (permalink / raw)
To: Ben Gelb; +Cc: linux-hams
On 28 Sep 2002, Ben Gelb wrote:
> Using fread with a large length doesn't work, because EOF is never found
> in stdin. So it just keeps waiting for the number of bytes specified.
Actually I Don't think it's EOF that is missed. You would expect to see
EOF only when the user disconnects. It's probably that the io stream is
fully buffered. Playing with the setbuf() family of functions (if
available in php, perl or whatever you use, I don't know) might be a
solution.
> I don't really understand why this works with the SEQPACKET
> consideration. I am definitely not getting the whole packet at once,
> yet, as I said, it does work.
Your code (which I believe in some form uses the libc stdio library)
buffers the reads and the actual low level read() is called with a buffer
larger than what you specify. The default is probably the machine page
size. I think that's why it works.
I have found that the safest option is to directly use a low level read()
call and handle any buffering my self. I don't know if that is an option
for you however. So after all your hack might the best solution.
--
Tomi Manninen Internet: oh2bns@sral.fi
OH2BNS AX.25: oh2bns@oh2rbi.fin.eu
KP20ME04 Amprnet: oh2bns@oh2rbi.ampr.org
^ permalink raw reply [flat|nested] 7+ messages in thread
* RE: ax25d and STDIN
2002-09-29 18:26 ` Tomi Manninen
@ 2002-09-29 22:14 ` Ben Gelb
0 siblings, 0 replies; 7+ messages in thread
From: Ben Gelb @ 2002-09-29 22:14 UTC (permalink / raw)
To: tpm; +Cc: linux-hams
I think I am going to stick with my hack. It works fine for the amount
of data I will be inputting at a time (less than 80 chars) so I don't
forsee any problems.
There is no real way to do a low-level read() in php, not that I am
aware of anyway, and the setbuf() family of functions doesn't exist.
Thanks for your help, perhaps I'll consider using C next time, but I
really want an uncompiled language so I can make changes quickly if
problems arise. I think I mentioned that before.
73 Ben
-----Original Message-----
From: linux-hams-owner@vger.kernel.org
[mailto:linux-hams-owner@vger.kernel.org] On Behalf Of Tomi Manninen
Sent: Sunday, September 29, 2002 2:27 PM
To: Ben Gelb
Cc: linux-hams@vger.kernel.org
Subject: Re: ax25d and STDIN
On 28 Sep 2002, Ben Gelb wrote:
> Using fread with a large length doesn't work, because EOF is never
found
> in stdin. So it just keeps waiting for the number of bytes specified.
Actually I Don't think it's EOF that is missed. You would expect to see
EOF only when the user disconnects. It's probably that the io stream is
fully buffered. Playing with the setbuf() family of functions (if
available in php, perl or whatever you use, I don't know) might be a
solution.
> I don't really understand why this works with the SEQPACKET
> consideration. I am definitely not getting the whole packet at once,
> yet, as I said, it does work.
Your code (which I believe in some form uses the libc stdio library)
buffers the reads and the actual low level read() is called with a
buffer
larger than what you specify. The default is probably the machine page
size. I think that's why it works.
I have found that the safest option is to directly use a low level
read()
call and handle any buffering my self. I don't know if that is an option
for you however. So after all your hack might the best solution.
--
Tomi Manninen Internet: oh2bns@sral.fi
OH2BNS AX.25: oh2bns@oh2rbi.fin.eu
KP20ME04 Amprnet: oh2bns@oh2rbi.ampr.org
-
To unsubscribe from this list: send the line "unsubscribe linux-hams" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2002-09-29 22:14 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2002-09-27 5:08 ax25d and STDIN Ben Gelb
2002-09-27 7:52 ` Tomi Manninen OH2BNS
2002-09-27 11:34 ` Ben Gelb
2002-09-27 23:09 ` Tomi Manninen
2002-09-28 5:19 ` Ben Gelb
2002-09-29 18:26 ` Tomi Manninen
2002-09-29 22:14 ` Ben Gelb
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.