summaryrefslogtreecommitdiff
path: root/src/mailbox.hpp
diff options
context:
space:
mode:
authorMartin Sustrik <sustrik@250bpm.com>2012-04-14 10:08:19 +0200
committerMartin Sustrik <sustrik@250bpm.com>2012-04-15 06:55:29 +0200
commitee66c579dedf7130aa4d59afbf373f28c98eead5 (patch)
tree2b29d8e236b02789877da88ecf05d5b463c046da /src/mailbox.hpp
parent19894e0a1b6fbbcb62028fc6513ef3904a6f5c76 (diff)
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 <sustrik@250bpm.com>
Diffstat (limited to 'src/mailbox.hpp')
-rw-r--r--src/mailbox.hpp33
1 files changed, 13 insertions, 20 deletions
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 <stddef.h>
-
-#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 <command_t, command_pipe_granularity> 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_);
}