|
|
Choosing A Webhost: |
CVS update of carob (include/JavaSocket.hpp src/JavaSocket.cpp): msg#00161db.carob.cvs
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
|
|
| <Prev in Thread] | Current Thread | [Next in Thread> |
|---|---|---|
| Previous by Date: | CVS update of carob (include/DriverSocket.hpp src/DriverSocket.cpp), gilles-Tt5JLJuBijYiZlD9aYmxOGD2FQJk+8+b |
|---|---|
| Next by Date: | CVS update of carob/test/10-Connection (TestConnect.cpp), gilles-Tt5JLJuBijYiZlD9aYmxOGD2FQJk+8+b |
| Previous by Thread: | CVS update of carob (include/JavaSocket.hpp src/JavaSocket.cpp), marc-Tt5JLJuBijYiZlD9aYmxOGD2FQJk+8+b |
| Next by Thread: | CVS update of carob (Makefile), marc-Tt5JLJuBijYiZlD9aYmxOGD2FQJk+8+b |
| Indexes: | [Date] [Thread] [Top] [All Lists] |
Free MagazinesCisco NewsReceive a free quarterly e-newsletter with exclusive articles on how Cisco IT uses its own products and solutions to enable the business. subscribe Systems Management News, the newspaper for IT systems administration and data center managers! Each issue of Systems Management News is chock-full of news and analysis to help you understand what's happening in your field. subscribe The Enterprise Newsweekly eWeek is the essential technology information source for builders of e-business. subscribe Oracle Magazine Oracle Magazine contains technology strategy articles, sample code, tips, Oracle and partner news, how to articles for developers and DBAs, and more. Oracle (NASDAQ: ORCL) is the world's largest enterprise software company. subscribe Total Telecom Total Telecom is "The Economist of the communications industry". subscribe |
Home
| advertise | OSDir is
an inevitable website.
|