From ee66c579dedf7130aa4d59afbf373f28c98eead5 Mon Sep 17 00:00:00 2001 From: Martin Sustrik Date: Sat, 14 Apr 2012 10:08:19 +0200 Subject: Report EMFILE/ENFILE from xs_socket() This patch propoagates the error from signaler and mailbox initialisation up the stack. To achieve this signaler and mailbox classes were re-written is C-like syntax. Finally, shutdown_stress test now ignores EMFILE/ENFILE errors. Thus, the tests should pass even on OSX which sets the max number of file descriptors pretty low by default. Signed-off-by: Martin Sustrik --- src/mailbox.hpp | 33 +++++++++++++-------------------- 1 file changed, 13 insertions(+), 20 deletions(-) (limited to 'src/mailbox.hpp') diff --git a/src/mailbox.hpp b/src/mailbox.hpp index e77364d..ea9dc08 100644 --- a/src/mailbox.hpp +++ b/src/mailbox.hpp @@ -22,32 +22,22 @@ #ifndef __XS_MAILBOX_HPP_INCLUDED__ #define __XS_MAILBOX_HPP_INCLUDED__ -#include - -#include "platform.hpp" #include "signaler.hpp" -#include "fd.hpp" #include "config.hpp" #include "command.hpp" #include "ypipe.hpp" #include "mutex.hpp" +#include "fd.hpp" namespace xs { - class mailbox_t - { - public: - - mailbox_t (); - ~mailbox_t (); - - fd_t get_fd (); - void send (const command_t &cmd_); - int recv (command_t *cmd_, int timeout_); - - private: + // Mailbox stores a list of commands sent to a particular object. + // Multiple threads can send commands to the mailbox in parallel. + // Only a single thread can read commands from the mailbox. + typedef struct + { // The pipe to store actual commands. typedef ypipe_t cpipe_t; cpipe_t cpipe; @@ -65,10 +55,13 @@ namespace xs // read commands from it. bool active; - // Disable copying of mailbox_t object. - mailbox_t (const mailbox_t&); - const mailbox_t &operator = (const mailbox_t&); - }; + } mailbox_t; + + int mailbox_init (mailbox_t *self_); + void mailbox_close (mailbox_t *self_); + fd_t mailbox_fd (mailbox_t *self_); + void mailbox_send (mailbox_t *self_, const command_t &cmd_); + int mailbox_recv (mailbox_t *self_, command_t *cmd_, int timeout_); } -- cgit v1.2.3