Re: Alarm signal and recv system call

Henry Cejtin <[email protected]> Thu, 15 Nov 2018 10:02:21 -0600
Newsgroups gmane.comp.lang.ml.mlton.user
Message-ID <CAPKXxCrXt_wi_OiaFS3oqdxO1-tSbkiv0Nsvxx46q5WozvhTsQ@mail.gmail.com>
You  have  to  remember  that  MLton  signal  handlers  are running in a
separate thread.  It gets passed the thread  that  was  interrupted  and
returns  the  thread to run when the handler is finished.  The result of
Handler.simple returns the thread it was called with, and hence restarts
the interrupted thread.

If  you  want the Socket.recvVec (or whatever) to be `aborted', then you
can't use Handler.simple to make the handler.  Instead you have to  have
some  other  thread to resume, or, if you want the program to terminate,
you have to terminate it in the handler.  You can do  the  latter  with,
for example, OS.Process.exit.

Doing this, your sample program would look like this:

    fun h = let val () = print "Alarm sig\n"
            in OS.Process.exit OS.Process.failure
            end
    val () = MLton.Signal.setHandler (Posix.Signal.arm,
                                      MLton.Signal.Handler.simple h)
    val () = Posix.Process.Alarm (Time.fromSeconds (Int.toLarge 3))
    val r = Socket.recvVec (socket, 1024)
    val () = print "Done\n"
On Thu, Nov 15, 2018 at 5:54 AM Kostirya <[email protected]> wrote:
>
> I was surprised to find that Alarm signal do not abort recvVec function.
> How is this possible?
> I thought recv was always aborted on signal.
>
>
> I use for test:
>
> val _ = MLton.Signal.setHandler(Posix.Signal.alrm,
> MLton.Signal.Handler.simple (fn _ => print "Alarm sig\n"))
> val _ = Posix.Process.alarm (Time.fromSeconds (Int.toLarge 3))
> val r = Socket.recvVec (socket, 1024)
> val _ = print "Done\n"
>
> --
> You received this message because you are subscribed to the Google Groups "MLton-user" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
>
>
>
> _______________________________________________
> MLton-user mailing list
> [email protected]; [email protected]
> https://lists.sourceforge.net/lists/listinfo/mlton-user

-- 
You received this message because you are subscribed to the Google Groups "MLton-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].