Date: Wednesday, January 25, 2006 @ 17:03:07
Author: gilles
Path: /cvsroot/carob/carob
Modified: include/JavaSocket.hpp (1.22 -> 1.23) src/JavaSocket.cpp (1.36
-> 1.37)
Added non-blocking option for socket creation (disabled = blocking by default)
------------------------+
include/JavaSocket.hpp | 5 ++++-
src/JavaSocket.cpp | 24 +++++++++++++++++++++++-
2 files changed, 27 insertions(+), 2 deletions(-)
Index: carob/include/JavaSocket.hpp
diff -u carob/include/JavaSocket.hpp:1.22 carob/include/JavaSocket.hpp:1.23
--- carob/include/JavaSocket.hpp:1.22 Wed Jan 18 18:02:25 2006
+++ carob/include/JavaSocket.hpp Wed Jan 25 17:03:07 2006
@@ -65,10 +65,13 @@
/**
* Creates the socket.
+ * @param blocking whether or not socket operations must be blocking (default
+ * is true, blocking socket)
* @return true upon successfull creation, false otherwise
* @throws ConnectionException
*/
- bool create() throw (ConnectionException, UnexpectedException);
+ bool create(bool blocking = true)
+ throw (ConnectionException, UnexpectedException);
/**
* Connects to the given host/port
* @param host the host to connect to as a string. Can be either numeric
Index: carob/src/JavaSocket.cpp
diff -u carob/src/JavaSocket.cpp:1.36 carob/src/JavaSocket.cpp:1.37
--- carob/src/JavaSocket.cpp:1.36 Tue Jan 24 11:39:05 2006
+++ carob/src/JavaSocket.cpp Wed Jan 25 17:03:07 2006
@@ -27,6 +27,7 @@
#include <netdb.h> // getaddrinfo() etc.
#include <netinet/tcp.h> // TCP_NODELAY etc.
#include <errno.h>
+#include <fcntl.h>
using std::wstring;
@@ -46,7 +47,8 @@
closeSocket();
}
-bool JavaSocket::create() throw (ConnectionException, UnexpectedException)
+bool JavaSocket::create(bool blocking /* = true */)
+ throw (ConnectionException, UnexpectedException)
{
wstring fctName(L"JavaSocket::Create");
if (isVerboseEnabled())
@@ -63,6 +65,26 @@
return false;
}
+ if (!blocking)
+ {
+ // Win: (to be tested)
+ // int var = 1;
+ // ioctlsocket(socketFd, FIONBIO, (u_long FAR*) &var);
+
+ // *nix:
+ int flags;
+ flags = fcntl(socketFd, F_GETFL, 0);
+ //Set non blocking
+ if (fcntl(socketFd, F_SETFL, flags | O_NONBLOCK) < 0)
+ //if above fcntl doesn't work, try this old way of doing it
+ //flags = 1;
+ //if (ioctl(socketFd, FIOBIO, &flags) < 0)
+ {
+ if (isErrorEnabled())
+ logError(fctName, L"Could not turn socket to non-blocking mode");
+ }
+ }
+ //Set socket options
int opt_value = 1;
if (setsockopt(socketFd, IPPROTO_TCP, TCP_NODELAY,
reinterpret_cast<char*>(&opt_value), sizeof opt_value) == -1
_______________________________________________
Carob-commits mailing list
[email protected]
https://forge.continuent.org/mailman/listinfo/carob-commits