Thanks.

So will you combine

  select(1024,{ 3 },{ },{ },{ 0.000000 })
  select(1024,{ },{ },{ },{ 0.010000 })

in

  select(1024,{ 3 },{ },{ },{ 0.010000 })

?

And

  select(1024,{ },{ },{ },{ 0.010000 })
  poll({ 3/POLLIN },1,0)

in

  poll({ 3/POLLIN },1, 0.010000)

?

And will you make this time (0.010000) adjustable also?


And one more question.
Please tell me, how to do it better.
I want cancel Socket.accept (Socket.recvVec, ...) call by signal or timeout.
For this I use loop select with 1 second timeout and check signal
flag. See code below.
It is duplication with repeatedly polling of PolyML.
Is it possible to make some kind of flag to tell to PolyML to cancel
repeatedly polling?



val stop = ref false
val _ = Signal.signal (Posix.Signal.term, Signal.SIG_HANDLE (fn _ =>
stop := true))


fun accept socket =
  let
    val t = Time.fromSeconds 1
    val sd = Socket.sockDesc socket
    fun doit socket = case Socket.select { rds = [sd], wrs = [], exs =
[], timeout = SOME t } of
        { rds = [sd], wrs = [], exs = [] } =>
        (case Socket.acceptNB socket of NONE (* Other worker was first
*) => doit socket | r => r)
      | _ => if !stop then NONE else doit socket
  in
    doit socket
  end


(* return "" if timeout or stop *)
fun read (socket, chunksize, (timeout:Time.time option)) =
  let
    val t = Time.fromSeconds 1
    val sd = Socket.sockDesc socket
    fun doit timeout = case Socket.select { rds = [sd], wrs = [], exs
= [], timeout = SOME t } of
        { rds = [sd], wrs = [], exs = [] } => Byte.bytesToString
(Socket.recvVec (socket, chunksize))
      | _ => (
        case timeout of
            NONE    => doit NONE
          | SOME tt => if Time.>(tt, t) then doit (SOME (Time.-(tt, t))) else ""
      )
  in
    doit timeout handle OS.SysErr ("Interrupted system call", _) => if
!stop then "" else doit timeout | exc => raise exc
  end
чт, 13 дек. 2018 г. в 16:54, David Matthews <david.matth...@prolingua.co.uk>:
>
> What you are seeing is Poly/ML repeatedly polling then blocking for a
> short while.  It doesn't use a blocking call or a long time-out because
> with multi-threading there's the possibility that another thread might
> interrupt it, perhaps as the result of a console interrupt.
>
> Actually, looking at the code I think it could be improved.  I'll have a
> look at it.
>
> David
>
> On 13/12/2018 09:01, Kostirya wrote:
> >    Hello.
> >    My application use select or poll before accept socket.
> >    I trace system calls and found that too many select or poll calls occur.
> >
> >    When I use select:
> >
> >    select(1024,{ },{ },{ },{ 0.010000 })            = 0 (0x0)
> >    select(1024,{ 3 },{ },{ },{ 0.000000 })          = 0 (0x0)
> >    select(1024,{ },{ },{ },{ 0.010000 })            = 0 (0x0)
> >    select(1024,{ 3 },{ },{ },{ 0.000000 })          = 0 (0x0)
> >    select(1024,{ },{ },{ },{ 0.010000 })            = 0 (0x0)
> >    ...
> >    select(1024,{ 3 },{ },{ },{ 0.000000 })          = 1 (0x1)
> >    accept(3,{ AF_INET 127.0.0.1:54121 },0xbb9f9c5c) = 4 (0x4)
> >
> >
> >    When I use poll and do *not* select:
> >
> >    poll({ 3/POLLIN },1,0)                 = 0 (0x0)
> >    select(1024,{ },{ },{ },{ 0.010000 })         = 0 (0x0)
> >    poll({ 3/POLLIN },1,0)                 = 0 (0x0)
> >    select(1024,{ },{ },{ },{ 0.010000 })         = 0 (0x0)
> >    poll({ 3/POLLIN },1,0)                 = 0 (0x0)
> >    select(1024,{ },{ },{ },{ 0.010000 })         = 0 (0x0)
> >    poll({ 3/POLLIN },1,0)                 = 1 (0x1)
> >    ...
> >    accept(3,{ AF_INET 127.0.0.1:48659 },0xbb9f9c5c) = 4 (0x4)
> >
> >
> >    My application wait incoming connection and do nothing but use 1-2% CPU.
> >
> >    What is it and why it is?
> >
> >    By the way.
> >    When I use kevent (epoll on linux) via FFI it is all right.
> >
> >    Nick.
> > _______________________________________________
> > polyml mailing list
> > polyml@inf.ed.ac.uk
> > http://lists.inf.ed.ac.uk/mailman/listinfo/polyml
> >
_______________________________________________
polyml mailing list
polyml@inf.ed.ac.uk
http://lists.inf.ed.ac.uk/mailman/listinfo/polyml

Reply via email to