Better way to timeout connect() when using libev?

2011-05-18 Thread Joachim Nilsson
Hi!

We use libev in Linux (2.6.35 on big/small endian ARM) for a simple
network client application where we want to timeout connect() attempts.

http://www.unixguide.net/network/socketfaq/3.5.shtml

For this purpose we use the following construct in a libev callback.

timeout = NULL_TIMER;
timeout.it_value.tv_sec = 10;
setitimer(ITIMER_REAL, timeout, NULL);
if (connect (...) == -1) { ... }
timeout = NULL_TIMER;
setitimer (ITIMER_REAL, timeout, NULL);

Is this OK for use with libev, or do you have any other recommendation?
Basically we're a bit concerned if it conflicts with the internal timer
implementation, or event loop, in libev.

Regards
 /Joachim

___
libev mailing list
libev@lists.schmorp.de
http://lists.schmorp.de/cgi-bin/mailman/listinfo/libev


Re: Better way to timeout connect() when using libev?

2011-05-18 Thread Joachim Nilsson
On 05/18/2011 12:45 PM, Marc Lehmann wrote:
 On Wed, May 18, 2011 at 10:43:15AM +0200, Joachim Nilsson 
 troglo...@gmail.com wrote:
 timeout.it_value.tv_sec = 10;
  setitimer(ITIMER_REAL, timeout, NULL);
  if (connect (...) == -1) { ... }
 timeout = NULL_TIMER;
 setitimer (ITIMER_REAL, timeout, NULL);
 Is this OK for use with libev?
 yes, although it defeats the purpose of using an event library when you
 then stop the whole program for a connect - if you know you have nothing
 else to do while you connect, this is fine though.

OK. (Yes, we're aware of the limitation... a full redesign is imminent,
but we need to ship sth asap.)

 or do you have any other recommendation?
 if you want to do sth. else, do a nonblocking connect (and use a normal
 libev timer and a write watcher to detect when the connect has finished).

Alright, as I suspected.  Which is also a better design. Thanks!

 Basically we're a bit concerned if it conflicts with the internal timer
 implementation, or event loop, in libev.
 No, you are safe as long as you handle SIGALRM (remember that sigalrm
 terminates your program). libev does not use sigalrm at the moment and
 there are no plans for it to ever use it, at least not by default.

Nice, I did not know that (that libev does not, or ever intend to rely
on SIGALRM). Very useful piece of information for us that are too lazy
to actually look at the implementation.

Thanks Marc!

Regards
 /Joachim


___
libev mailing list
libev@lists.schmorp.de
http://lists.schmorp.de/cgi-bin/mailman/listinfo/libev


Re: [PATCH 2] fix broken strict aliasing

2010-02-25 Thread Joachim Nilsson
On Thu, Feb 25, 2010 at 9:20 AM, Gabriel Kerneis kern...@pps.jussieu.fr wrote:
 On Wed, Feb 24, 2010 at 07:33:39PM +0100, Marc Lehmann wrote:
 Well, it's not fundamentally complicated.
 It was pretty enlightning for me, many thanks.

Same here, actually one of the most interesting threads ever on this
list.  Many thanks Marc!

Regards
 /Joachim

___
libev mailing list
libev@lists.schmorp.de
http://lists.schmorp.de/cgi-bin/mailman/listinfo/libev


Re: POLL: disable signalfd usage by default?

2009-11-18 Thread Joachim Nilsson
Fantastic!

Yep, headers and everything line up quite nicely.  Thanks for the
heads-up, good for others reading the list!

Regards
 /Jocke

On Wed, Nov 18, 2009 at 9:09 PM, Marc Lehmann schm...@schmorp.de wrote:
 On Wed, Nov 18, 2009 at 09:02:36PM +0100, Joachim Nilsson 
 troglo...@gmail.com wrote:
 running 2.6.27.  If there are runtime checks everything will be fine,
 but there could be configure options, or built-in configure probes,
 that don't check for cross-compilation, I've run into such beasts
 before.

 No, everything is detected properly at runtime, as long as your headers
 match your libc and your libcs match themselves.

 --
                The choice of a       Deliantra, the free code+content MORPG
      -==-     _GNU_              http://www.deliantra.net
      ==-- _       generation
      ---==---(_)__  __   __      Marc Lehmann
      --==---/ / _ \/ // /\ \/ /      ...@goof.com
      -=/_/_//_/\_,_/ /_/\_\


___
libev mailing list
libev@lists.schmorp.de
http://lists.schmorp.de/cgi-bin/mailman/listinfo/libev


Re: semaphore usage in libev?

2009-11-18 Thread Joachim Nilsson
Just a forward to the list of my grateful reply to Mr. Lehmann.

 /Joachim

On Wed, Nov 18, 2009 at 9:16 PM, Joachim Nilsson troglo...@gmail.com wrote:
 Great, thanks Marc!
 :-)

 Btw, you've got some awesome turnaround time on replies, I must say.
 Thank you so much!

 Regards
  /Jocke

 On Wed, Nov 18, 2009 at 9:08 PM, Marc Lehmann schm...@schmorp.de wrote:
 On Wed, Nov 18, 2009 at 08:59:03PM +0100, Joachim Nilsson 
 troglo...@gmail.com wrote:
 Do you have any recommendations regarding the use of semaphores with
 libev?  I.e. does it work, or should I try and avoid semaphores from
 some particular watcher type?

 I think it's two rather orthogonal things - libev doesn't use any kind of
 semaphores internally, so will hardly collide.

 I looked around a bit, but couldn't seem to find any mention of best
 practices, or such, in the documentation or the mailing list.

 I guess you cna safely treta it like many other thing not mentioned in the
 documentation, such as does it work with prime numbers, does it work with
 my toaster, will it interfere with iceweasel on the same system.

 You typically run into problems if you mix multiple event libraries, as
 most event sources under unix are single-use points (signals for example),
 but since libev doesn't use semaphores itself, you are safe.

 --
                The choice of a       Deliantra, the free code+content MORPG
      -==-     _GNU_              http://www.deliantra.net
      ==-- _       generation
      ---==---(_)__  __   __      Marc Lehmann
      --==---/ / _ \/ // /\ \/ /      ...@goof.com
      -=/_/_//_/\_,_/ /_/\_\



___
libev mailing list
libev@lists.schmorp.de
http://lists.schmorp.de/cgi-bin/mailman/listinfo/libev


Re: ev_io and message queues

2009-03-29 Thread Joachim Nilsson
Hi!

Just wanted to let you know that POSIX message queues works perfectly
with libev!
See this blog entry about my experiences, and some code examples thus far:

   http://vmlinux.org/jocke/blog/hacks/libev-message-queues

Thanks for a great library!

Regards
 /Joachim

___
libev mailing list
libev@lists.schmorp.de
http://lists.schmorp.de/cgi-bin/mailman/listinfo/libev


ev_io and message queues

2009-03-27 Thread Joachim Nilsson
Hi!

My name is Joachim and I'm new to this list. I've just started
evaluating libev as a possible replacement for a homebrew timer
implementation (based on Don Libes Implementing Software Timers).

So far so good, the timers are easily replaceable.

My next hurdle was refactoring a state machine implemented with System
V message queues, msgget()/msgsnd()/msgrcv(). In particular I tried
connecting an ev_io watcher to the message queue identifier, which is
rumored to be a standard file descriptor in Linux. No luck so far.

So I have two questions:

1) Is this even possible? Can I use any POSIX message queue primitives
with ev_io or should I attempt a redesign using standard file
descriptors or pipes?

2) Does anyone have any other neat idea how to integrate ev_io with
message passing?

If it helps, in my design I have a couple of processes (threads
actually) that generate events from external stimuli (incoming packets
and TIPC messages) and timeouts.  Currently they relay these events
using msgsnd() to a separate process that does msgrcv() and a big
switch-case. The same switch-case can then generate new events to
itself, e.g. start a new timer.

Thanks for a great library!

Regards
 /Joachim

___
libev mailing list
libev@lists.schmorp.de
http://lists.schmorp.de/cgi-bin/mailman/listinfo/libev