refactor: TCPSocket, new protected methods to access m_readable, m_writable and m_connected, use them in place of direct access and make the variables private
TCPSocket, remove duplicate private and protected sections in header
This commit is contained in:
parent
c327c80d63
commit
9db11a90eb
2 changed files with 36 additions and 11 deletions
|
|
@ -88,7 +88,7 @@ ISocketMultiplexerJob *SecureSocket::newJob()
|
||||||
{
|
{
|
||||||
// after TCP connection is established, SecureSocket will pick up
|
// after TCP connection is established, SecureSocket will pick up
|
||||||
// connected event and do secureConnect
|
// connected event and do secureConnect
|
||||||
if (m_connected && !m_secureReady) {
|
if (isConnected() && !m_secureReady) {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -155,11 +155,11 @@ TCPSocket::JobResult SecureSocket::doRead()
|
||||||
// has therefore shutdown but don't flush our buffer
|
// has therefore shutdown but don't flush our buffer
|
||||||
// since there's still data to be read.
|
// since there's still data to be read.
|
||||||
sendEvent(EventTypes::StreamInputShutdown);
|
sendEvent(EventTypes::StreamInputShutdown);
|
||||||
if (!m_writable && m_inputBuffer.getSize() == 0) {
|
if (!isWritable() && m_inputBuffer.getSize() == 0) {
|
||||||
sendEvent(EventTypes::SocketDisconnected);
|
sendEvent(EventTypes::SocketDisconnected);
|
||||||
m_connected = false;
|
setConnected(false);
|
||||||
}
|
}
|
||||||
m_readable = false;
|
setReadable(false);
|
||||||
return New;
|
return New;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -565,7 +565,7 @@ void SecureSocket::checkResult(int status, int &retry)
|
||||||
// Need to make sure the socket is known to be writable so the impending
|
// Need to make sure the socket is known to be writable so the impending
|
||||||
// select action actually triggers on a write. This isn't necessary for
|
// select action actually triggers on a write. This isn't necessary for
|
||||||
// m_readable because the socket logic is always readable
|
// m_readable because the socket logic is always readable
|
||||||
m_writable = true;
|
setWritable(true);
|
||||||
retry++;
|
retry++;
|
||||||
LOG((CLOG_DEBUG2 "want to write, error=%d, attempt=%d", errorCode, retry));
|
LOG((CLOG_DEBUG2 "want to write, error=%d, attempt=%d", errorCode, retry));
|
||||||
break;
|
break;
|
||||||
|
|
|
||||||
|
|
@ -79,15 +79,42 @@ protected:
|
||||||
|
|
||||||
void setJob(ISocketMultiplexerJob *);
|
void setJob(ISocketMultiplexerJob *);
|
||||||
|
|
||||||
|
bool isConnected() const
|
||||||
|
{
|
||||||
|
return m_connected;
|
||||||
|
}
|
||||||
|
|
||||||
|
void setConnected(bool connected)
|
||||||
|
{
|
||||||
|
if (m_connected == connected)
|
||||||
|
return;
|
||||||
|
m_connected = connected;
|
||||||
|
}
|
||||||
|
|
||||||
bool isReadable() const
|
bool isReadable() const
|
||||||
{
|
{
|
||||||
return m_readable;
|
return m_readable;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void setReadable(bool readable)
|
||||||
|
{
|
||||||
|
if (m_readable == readable)
|
||||||
|
return;
|
||||||
|
m_readable = readable;
|
||||||
|
}
|
||||||
|
|
||||||
bool isWritable() const
|
bool isWritable() const
|
||||||
{
|
{
|
||||||
return m_writable;
|
return m_writable;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void setWritable(bool canWrite)
|
||||||
|
{
|
||||||
|
if (canWrite == m_writable)
|
||||||
|
return;
|
||||||
|
m_writable = canWrite;
|
||||||
|
}
|
||||||
|
|
||||||
Mutex &getMutex()
|
Mutex &getMutex()
|
||||||
{
|
{
|
||||||
return m_mutex;
|
return m_mutex;
|
||||||
|
|
@ -96,6 +123,10 @@ protected:
|
||||||
void sendEvent(EventTypes);
|
void sendEvent(EventTypes);
|
||||||
void discardWrittenData(int bytesWrote);
|
void discardWrittenData(int bytesWrote);
|
||||||
|
|
||||||
|
IEventQueue *m_events;
|
||||||
|
StreamBuffer m_inputBuffer;
|
||||||
|
StreamBuffer m_outputBuffer;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void init();
|
void init();
|
||||||
|
|
||||||
|
|
@ -108,15 +139,9 @@ private:
|
||||||
ISocketMultiplexerJob *serviceConnecting(ISocketMultiplexerJob *, bool, bool, bool);
|
ISocketMultiplexerJob *serviceConnecting(ISocketMultiplexerJob *, bool, bool, bool);
|
||||||
ISocketMultiplexerJob *serviceConnected(ISocketMultiplexerJob *, bool, bool, bool);
|
ISocketMultiplexerJob *serviceConnected(ISocketMultiplexerJob *, bool, bool, bool);
|
||||||
|
|
||||||
protected:
|
|
||||||
bool m_readable;
|
bool m_readable;
|
||||||
bool m_writable;
|
bool m_writable;
|
||||||
bool m_connected;
|
bool m_connected;
|
||||||
IEventQueue *m_events;
|
|
||||||
StreamBuffer m_inputBuffer;
|
|
||||||
StreamBuffer m_outputBuffer;
|
|
||||||
|
|
||||||
private:
|
|
||||||
Mutex m_mutex;
|
Mutex m_mutex;
|
||||||
ArchSocket m_socket;
|
ArchSocket m_socket;
|
||||||
CondVar<bool> m_flushed;
|
CondVar<bool> m_flushed;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue