To Cense about Signal ()

new topic     » topic index » view thread      » older message » newer message

First off, let me start by saying I will name every child I have from this day
forward after  you, with
different middle names of course, as it could get really confusing otherwise. .
.  .

Now that I've done my schmoozing, there is a comment and a couple of questions
left:

Your suggestions on Send() worked perfectly and I understand the wrapper for
signal() that you wrote. My
question or two about it is, considering my previous example of write(now send),
assuming that the SIGPIPE
would be returned before send() has a chance to return -1, when would you run
the signal()? Is this
something that needs to be run only once, and it will work for the duration or
does it need to be called
before each instance of send()? The other question is, once the Signal() is
caught, and the specified
routine run, do you have any idea if the main program will continue the send()
or does it skip to the next
line in the sending routine?

In other words, If I send() "message" signal() should direct the call_back to
run a simple routine at the
beginning of the message. Does it continue to try to send the message, thus
running signal() for
length("message") times?

Any more help at this point might seem a tad greedy but your message came
literally five minutes after I had
given up all hope and was opening up my many C manuals to begin re-coding my
game yet another time.

Thank you again,  Cense, you've been a life saver.

Kayhlan

cense wrote:

> On Tue, 14 Nov 2000, Kayhlan wrote:
> >> Being an avid Euphoria user, but admittedly a very novice C user I actually
> >> have more questions about your questions than I do answers.
>
> Im not C expert myself, infact i was just in your position a little while ago.
>
> >> First, man 2 write when talking about error messages lists EPIPE "fd is
> >> connected to a pipe or socket
> >> whose reading end is closed. When this happens, the writing process will
> >> receive a SIGPIPE signal: if
> >> it catches, blocks or ignores this error, EPIPE is returned."
>
> hehe, now i see that part of the man page, stupid me
>
> >> Questions about this:
> >>
> >> You say errno would be set properly, but how is this passed into Euphoria?
> >> Do I have to make a global integer in Euphoria or is this just not
> >> possible?
>
> Now again, i dont know a whole lot about C like others on this list (Bernie
> Ryan for sure knows his C programming) but i know that errno is a variable
> declared as "extern int errno" in the include <errno.h>
>
> As far as i know there is no way to access this variable from Euphoria other
> than perhaps peeking into the memory where errno is allocated but i do not
> know
> how to do this myself. Give Bernie Ryan or other more highly qualified C guys
> a
> shout about that question
>
> >> As I said, I have never recorded xxx equal to anything but the length of
> >> the data sent.
> >> (Possibly because the time it would return -1 it terminates with the broken
> >> pipe)
>
> I agree with this theory of why you are never getting -1
>
> >> I do use recv() instead of read, however I cannot make Euphoria pass
> >> strings to C so I have been
> >> unable to get send() to work properly.
>
> to get Euphoria to pass a string to a C routine, you need to put your sequence
> (the euphoria string) into memory ala C style. This can be accomplished using
> a
> simple function like this:
>
> function alloc_string( sequence str )
>   atom ptr
>
>   ptr = allocate( length( str ) + 1 )
>   poke( ptr, str & 0 )
>
>   return ptr
> end function
>
> A C compliant pointer is returned by alloc_string which can be used in
> wherever
> a "char *" is needed. In your case, the second argument to send( )
>
> send can also accept pointers to any type of data so if you are not sending
> strings, it will work exactly the same.
>
> >> And as far as "catching" the signal, other than poll() (which is not
> >> catching the disconnect all the
> >> time) I have no clue how to go about detecting the disconnection another
> >> way. Is there some function
> >> that would test a socket to see if it is still active?
>
> To "catch" a signal sent to a process, you have to install a new signal
> handler
> by using the function "signal( )". the man 2 signal page has some info on
> signal but its still kinda confusing so i can give you a little extra help on
> that. I have a wrapper for "signal( )" that i *think* works but i have not
> tested it, it goes as follows:
>
> function signal( int signum, int routine )
>   atom sig_handler_ptr, ret_ptr
>
>   sig_handler_ptr = call_back( routine )
>   ret_ptr = c_func( signal_, { signum, sig_handler_ptr } )
>
>   if ret_ptr = sig_handler_ptr then
>     return 0
>   else
>     return 1
>   end if
> end function
>
> Now for my documentation. signal( ) above takes two arguments, the first is
> the
> signal number you want "catch" (in your case SIGPIPE or 13). The second
> argument is the routine_id of the function that you will be using to handle
> the
> signal when it is recived. You can get the routine_id of any function in
> euphoria by using "routine_id( s )" check the Euphoria reference manual for
> details.
>
> If you need some more help with signal or if you dont understand my
> rambling, mail back once more and i will try to be a little more clear and
> in-depth.
>
> >> thanks very much for your help so far,
>
> No problem, this is what the mailing list is for!
>
> >> Kayhlan
>
> --
> evil, corruption and bad taste
> ^[cense]

new topic     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu