summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Sustrik <sustrik@250bpm.com>2012-02-16 10:28:49 +0900
committerMartin Sustrik <sustrik@250bpm.com>2012-02-16 10:28:49 +0900
commita0d548e6cdef36a8dae6e6834252475728bf8583 (patch)
treec5f91d31926322bab95143d7f6e91c35bd37ac04
parent8bf03ce698c49d26bed3079003e59243b72af05a (diff)
ZMQ_REENTRANT functionality removed
It doesn't play well with multipart messages. Signed-off-by: Martin Sustrik <sustrik@250bpm.com>
-rw-r--r--builds/msvc/tests/tests.vcxproj6
-rw-r--r--builds/msvc/tests/tests.vcxproj.filters5
-rw-r--r--doc/xs_setctxopt.txt16
-rw-r--r--include/xs.h1
-rw-r--r--src/ctx.cpp21
-rw-r--r--src/ctx.hpp6
-rw-r--r--src/socket_base.cpp13
-rw-r--r--src/socket_base.hpp9
-rw-r--r--src/xs.cpp12
-rw-r--r--tests/Makefile.am2
-rw-r--r--tests/reentrant.cpp53
11 files changed, 3 insertions, 141 deletions
diff --git a/builds/msvc/tests/tests.vcxproj b/builds/msvc/tests/tests.vcxproj
index 6ed83cf..d62597d 100644
--- a/builds/msvc/tests/tests.vcxproj
+++ b/builds/msvc/tests/tests.vcxproj
@@ -113,10 +113,6 @@
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
</ClCompile>
- <ClCompile Include="..\..\..\tests\reentrant.cpp">
- <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
- <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
- </ClCompile>
<ClCompile Include="..\..\..\tests\reqrep_device.cpp">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
@@ -162,4 +158,4 @@
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
-</Project> \ No newline at end of file
+</Project>
diff --git a/builds/msvc/tests/tests.vcxproj.filters b/builds/msvc/tests/tests.vcxproj.filters
index 5088626..01121cb 100644
--- a/builds/msvc/tests/tests.vcxproj.filters
+++ b/builds/msvc/tests/tests.vcxproj.filters
@@ -47,9 +47,6 @@
<ClCompile Include="..\..\..\tests\timeo.cpp">
<Filter>Header Files</Filter>
</ClCompile>
- <ClCompile Include="..\..\..\tests\reentrant.cpp">
- <Filter>Header Files</Filter>
- </ClCompile>
<ClCompile Include="..\..\..\tests\max_sockets.cpp">
<Filter>Header Files</Filter>
</ClCompile>
@@ -67,4 +64,4 @@
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
-</Project> \ No newline at end of file
+</Project>
diff --git a/doc/xs_setctxopt.txt b/doc/xs_setctxopt.txt
index be7d06f..dded922 100644
--- a/doc/xs_setctxopt.txt
+++ b/doc/xs_setctxopt.txt
@@ -34,22 +34,6 @@ Option value type:: int
Option value unit:: sockets
Default value:: 512
-XS_REENTRANT: Specify whether sockets should be thread-safe
-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-If 'XS_REENTRANT' option is set to 1 it is safe to access single Crossroads
-socket from multiple threads in parallel. If it is set to 0 it can be accessed
-by at most one thread at any single point of time.
-
-Note: By default Crossroads sockets are non-reentrant. If possible, try to use
-the socket from the thread it was created in. If communication between threads
-is needed use inproc transport. Not following this advice can introduce
-scalability problems.
-
-[horizontal]
-Option value type:: int
-Option value unit:: boolean
-Default value:: 0
-
RETURN VALUE
------------
The _xs_setctxopt()_ function shall return zero if successful. Otherwise it
diff --git a/include/xs.h b/include/xs.h
index d536f19..098ea5a 100644
--- a/include/xs.h
+++ b/include/xs.h
@@ -147,7 +147,6 @@ XS_EXPORT int xs_getmsgopt (xs_msg_t *msg, int option, void *optval,
/******************************************************************************/
#define XS_MAX_SOCKETS 1
-#define XS_REENTRANT 2
XS_EXPORT void *xs_init (int io_threads);
XS_EXPORT int xs_term (void *context);
diff --git a/src/ctx.cpp b/src/ctx.cpp
index 789cdc2..98d3b86 100644
--- a/src/ctx.cpp
+++ b/src/ctx.cpp
@@ -47,8 +47,7 @@ xs::ctx_t::ctx_t (uint32_t io_threads_) :
monitor (NULL),
log_socket (NULL),
max_sockets (512),
- io_thread_count (io_threads_),
- reentrant (false)
+ io_thread_count (io_threads_)
{
}
@@ -154,16 +153,6 @@ int xs::ctx_t::setctxopt (int option_, const void *optval_, size_t optvallen_)
max_sockets = *((int*) optval_);
opt_sync.unlock ();
break;
- case XS_REENTRANT:
- if (optvallen_ != sizeof (int) || (*((int*) optval_) != 0 &&
- *((int*) optval_) != 1)) {
- errno = EINVAL;
- return -1;
- }
- opt_sync.lock ();
- reentrant = (*((int*) optval_) ? true : false);
- opt_sync.unlock ();
- break;
default:
errno = EINVAL;
return -1;
@@ -396,14 +385,6 @@ void xs::ctx_t::publish_logs (const char *text_)
log_sync.unlock ();
}
-bool xs::ctx_t::is_reentrant ()
-{
- opt_sync.lock ();
- bool ret = reentrant;
- opt_sync.unlock ();
- return ret;
-}
-
// The last used socket ID, or 0 if no socket was used so far. Note that this
// is a global variable. Thus, even sockets created in different contexts have
// unique IDs.
diff --git a/src/ctx.hpp b/src/ctx.hpp
index e912443..56b5d4c 100644
--- a/src/ctx.hpp
+++ b/src/ctx.hpp
@@ -100,9 +100,6 @@ namespace xs
void log (int sid_, const char *text_);
void publish_logs (const char *text_);
- // True, if API is expected to be reentrant.
- bool is_reentrant ();
-
enum {
term_tid = 0,
reaper_tid = 1
@@ -176,9 +173,6 @@ namespace xs
// Number of I/O threads to launch.
uint32_t io_thread_count;
- // True, if API is expected to be reentrant.
- bool reentrant;
-
// Synchronisation of access to context options.
mutex_t opt_sync;
diff --git a/src/socket_base.cpp b/src/socket_base.cpp
index 7ab00ea..38ec8c1 100644
--- a/src/socket_base.cpp
+++ b/src/socket_base.cpp
@@ -117,7 +117,6 @@ xs::socket_base_t *xs::socket_base_t::create (int type_, class ctx_t *parent_,
xs::socket_base_t::socket_base_t (ctx_t *parent_, uint32_t tid_, int sid_) :
own_t (parent_, tid_),
tag (0xbaddecaf),
- reentrant (parent_->is_reentrant ()),
ctx_terminated (false),
destroyed (false),
last_tsc (0),
@@ -146,18 +145,6 @@ void xs::socket_base_t::stop ()
send_stop ();
}
-void xs::socket_base_t::lock ()
-{
- if (reentrant)
- sync.lock ();
-}
-
-void xs::socket_base_t::unlock ()
-{
- if (reentrant)
- sync.unlock ();
-}
-
int xs::socket_base_t::parse_uri (const char *uri_,
std::string &protocol_, std::string &address_)
{
diff --git a/src/socket_base.hpp b/src/socket_base.hpp
index dd1fee7..16f7c61 100644
--- a/src/socket_base.hpp
+++ b/src/socket_base.hpp
@@ -65,10 +65,6 @@ namespace xs
// This function can be called from a different thread!
void stop ();
- // Synchronise access of application threads to the socket.
- void lock ();
- void unlock ();
-
// Interface for communication with the API layer.
int setsockopt (int option_, const void *optval_, size_t optvallen_);
int getsockopt (int option_, void *optval_, size_t *optvallen_);
@@ -145,11 +141,6 @@ namespace xs
// Used to check whether the object is a socket.
uint32_t tag;
- // Synchronisation of access to the socket. If Crossroads are running
- // in non-reentrant mode, it is a dummy mutex-like object.
- bool reentrant;
- mutex_t sync;
-
// If true, associated context was already terminated.
bool ctx_terminated;
diff --git a/src/xs.cpp b/src/xs.cpp
index a4ed3a1..99a3bae 100644
--- a/src/xs.cpp
+++ b/src/xs.cpp
@@ -180,9 +180,7 @@ int xs_setsockopt (void *s_, int option_, const void *optval_,
errno = ENOTSOCK;
return -1;
}
- s->lock ();
int rc = s->setsockopt (option_, optval_, optvallen_);
- s->unlock ();
return rc;
}
@@ -193,9 +191,7 @@ int xs_getsockopt (void *s_, int option_, void *optval_, size_t *optvallen_)
errno = ENOTSOCK;
return -1;
}
- s->lock ();
int rc = s->getsockopt (option_, optval_, optvallen_);
- s->unlock ();
return rc;
}
@@ -206,9 +202,7 @@ int xs_bind (void *s_, const char *addr_)
errno = ENOTSOCK;
return -1;
}
- s->lock ();
int rc = s->bind (addr_);
- s->unlock ();
return rc;
}
@@ -219,9 +213,7 @@ int xs_connect (void *s_, const char *addr_)
errno = ENOTSOCK;
return -1;
}
- s->lock ();
int rc = s->connect (addr_);
- s->unlock ();
return rc;
}
@@ -281,9 +273,7 @@ int xs_sendmsg (void *s_, xs_msg_t *msg_, int flags_)
return -1;
}
int sz = (int) xs_msg_size (msg_);
- s->lock ();
int rc = s->send ((xs::msg_t*) msg_, flags_);
- s->unlock ();
if (unlikely (rc < 0))
return -1;
return sz;
@@ -296,9 +286,7 @@ int xs_recvmsg (void *s_, xs_msg_t *msg_, int flags_)
errno = ENOTSOCK;
return -1;
}
- s->lock ();
int rc = s->recv ((xs::msg_t*) msg_, flags_);
- s->unlock ();
if (unlikely (rc < 0))
return -1;
return (int) xs_msg_size (msg_);
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 520b2cf..7b7488e 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -19,7 +19,6 @@ noinst_PROGRAMS = pair_inproc \
reqrep_ipc \
timeo \
max_sockets \
- reentrant \
emptyctx
pair_inproc_SOURCES = pair_inproc.cpp testutil.hpp
@@ -38,7 +37,6 @@ pair_ipc_SOURCES = pair_ipc.cpp testutil.hpp
reqrep_ipc_SOURCES = reqrep_ipc.cpp testutil.hpp
timeo_SOURCES = timeo.cpp
max_sockets_SOURCES = max_sockets.cpp
-reentrant_SOURCES = reentrant.cpp testutil.hpp
emptyctx_SOURCES = emptyctx.cpp
TESTS = $(noinst_PROGRAMS)
diff --git a/tests/reentrant.cpp b/tests/reentrant.cpp
deleted file mode 100644
index 2832b1e..0000000
--- a/tests/reentrant.cpp
+++ /dev/null
@@ -1,53 +0,0 @@
-/*
- Copyright (c) 2012 250bpm s.r.o.
- Copyright (c) 2012 Other contributors as noted in the AUTHORS file
-
- This file is part of Crossroads project.
-
- Crossroads is free software; you can redistribute it and/or modify it under
- the terms of the GNU Lesser General Public License as published by
- the Free Software Foundation; either version 3 of the License, or
- (at your option) any later version.
-
- Crossroads is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU Lesser General Public License for more details.
-
- You should have received a copy of the GNU Lesser General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
-*/
-
-#include "testutil.hpp"
-
-int XS_TEST_MAIN ()
-{
- fprintf (stderr, "reentrant test running...\n");
-
- // Initialise the context and set REENTRANT option.
- void *ctx = xs_init (1);
- assert (ctx);
- int val = 1;
- int rc = xs_setctxopt (ctx, XS_REENTRANT, &val, sizeof (val));
- assert (rc == 0);
-
- // Do a set of operations to make sure that REENTRANT option doesn't
- // break anything.
- void *sb = xs_socket (ctx, XS_REP);
- assert (sb);
- rc = xs_bind (sb, "inproc://a");
- assert (rc == 0);
- void *sc = xs_socket (ctx, XS_REQ);
- assert (sc);
- rc = xs_connect (sc, "inproc://a");
- assert (rc == 0);
- bounce (sb, sc);
- rc = xs_close (sc);
- assert (rc == 0);
- rc = xs_close (sb);
- assert (rc == 0);
- rc = xs_term (ctx);
- assert (rc == 0);
-
- return 0 ;
-}