[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: kdenonbeta/libqt-addon/libqt-addon
From: Thiago Macieira <thiagom () mail ! com>
Date: 2003-12-10 21:28:04
[Download RAW message or body]
CVS commit by thiago:
Added virtual disconnect method
M +38 -22 qsocketimpl.cpp 1.9
M +11 -3 qsocketimpl.h 1.8
--- kdenonbeta/libqt-addon/libqt-addon/qsocketimpl.h #1.7:1.8
@@ -82,5 +82,5 @@ public:
* Returns the file descriptor for this socket.
*/
- inline int socket()
+ inline int socket() const
{ return m_sockfd; }
@@ -136,4 +136,9 @@ public:
/**
+ * Disconnects this socket.
+ */
+ virtual bool disconnect();
+
+ /**
* Returns the number of bytes available for reading without blocking.
*/
@@ -142,4 +147,7 @@ public:
/**
* Waits up to @p msecs for more data to be available on this socket.
+ *
+ * This function is a wrapper against @ref poll. This function will wait
+ * for any read events.
*/
virtual Q_LONG waitForMore(int msecs, bool *timeout = 0L);
--- kdenonbeta/libqt-addon/libqt-addon/qsocketimpl.cpp #1.8:1.9
@@ -344,4 +344,38 @@ QSocketImpl* QSocketImpl::accept()
}
+bool QSocketImpl::disconnect()
+{
+ resetError();
+
+ if (m_sockfd == -1)
+ return false; // can't create
+
+ QSocketAddress address;
+ address.setFamily(AF_UNSPEC);
+ if (::qt_socket_connect(m_sockfd, address.address(), address.length()) == -1)
+ {
+ if (errno == EALREADY || errno == EINPROGRESS)
+ {
+ setError(IO_ConnectError, InProgress);
+ return false;
+ }
+ else if (errno == ECONNREFUSED)
+ setError(IO_ConnectError, ConnectionRefused);
+ else if (errno == ENETDOWN || errno == ENETUNREACH ||
+ errno == ENETRESET || errno == ECONNABORTED ||
+ errno == ECONNRESET || errno == EHOSTDOWN ||
+ errno == EHOSTUNREACH)
+ setError(IO_ConnectError, NetFailure);
+ else
+ setError(IO_ConnectError, NotSupported);
+
+ return false;
+ }
+
+ setFlags(IO_Sequential | IO_Raw | IO_ReadWrite);
+ setState(IO_Open);
+ return true; // all is well
+}
+
Q_LONG QSocketImpl::bytesAvailable() const
{
@@ -361,25 +395,7 @@ Q_LONG QSocketImpl::waitForMore(int msec
return -1; // there won't ever be anything to read...
- struct timeval tv;
- tv.tv_sec = msecs / 1000;
- tv.tv_usec = (msecs % 1000) * 1000;
-
- fd_set fds;
- FD_ZERO(&fds);
- FD_SET(m_sockfd, &fds);
-
- int retval;
-
- if (msecs == -1)
- // block indefinetely
- retval = select(m_sockfd + 1, &fds, NULL, NULL, NULL);
- else
- retval = select(m_sockfd + 1, &fds, NULL, NULL, &tv);
-
- if (timeout)
- *timeout = retval == 0; // set if there was a timeout
- if (retval == -1)
- // error occurred!
- return -1;
+ bool input;
+ if (!poll(&input, 0, 0, msecs, timeout))
+ return -1; // failed polling
return bytesAvailable();
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic