mirror of
https://github.com/debauchee/barrier.git
synced 2026-02-12 14:45:21 +08:00
Make ownership of SocketMultiplexerJob explicit
This commit is contained in:
@@ -83,7 +83,7 @@ SecureSocket::~SecureSocket()
|
||||
// take socket from multiplexer ASAP otherwise the race condition
|
||||
// could cause events to get called on a dead object. TCPSocket
|
||||
// will do this, too, but the double-call is harmless
|
||||
setJob(NULL);
|
||||
removeJob();
|
||||
freeSSLResources();
|
||||
|
||||
// removing sleep() because I have no idea why you would want to do it
|
||||
@@ -125,13 +125,12 @@ SecureSocket::connect(const NetworkAddress& addr)
|
||||
TCPSocket::connect(addr);
|
||||
}
|
||||
|
||||
ISocketMultiplexerJob*
|
||||
SecureSocket::newJob()
|
||||
std::unique_ptr<ISocketMultiplexerJob> SecureSocket::newJob()
|
||||
{
|
||||
// after TCP connection is established, SecureSocket will pick up
|
||||
// connected event and do secureConnect
|
||||
if (m_connected && !m_secureReady) {
|
||||
return NULL;
|
||||
return {};
|
||||
}
|
||||
|
||||
return TCPSocket::newJob();
|
||||
@@ -140,7 +139,7 @@ SecureSocket::newJob()
|
||||
void
|
||||
SecureSocket::secureConnect()
|
||||
{
|
||||
setJob(new TSocketMultiplexerMethodJob<SecureSocket>(
|
||||
setJob(std::make_unique<TSocketMultiplexerMethodJob<SecureSocket>>(
|
||||
this, &SecureSocket::serviceConnect,
|
||||
getSocket(), isReadable(), isWritable()));
|
||||
}
|
||||
@@ -148,7 +147,7 @@ SecureSocket::secureConnect()
|
||||
void
|
||||
SecureSocket::secureAccept()
|
||||
{
|
||||
setJob(new TSocketMultiplexerMethodJob<SecureSocket>(
|
||||
setJob(std::make_unique<TSocketMultiplexerMethodJob<SecureSocket>>(
|
||||
this, &SecureSocket::serviceAccept,
|
||||
getSocket(), isReadable(), isWritable()));
|
||||
}
|
||||
@@ -740,10 +739,11 @@ SecureSocket::verifyCertFingerprint()
|
||||
return isValid;
|
||||
}
|
||||
|
||||
ISocketMultiplexerJob*
|
||||
SecureSocket::serviceConnect(ISocketMultiplexerJob* job,
|
||||
bool, bool write, bool error)
|
||||
MultiplexerJobStatus SecureSocket::serviceConnect(ISocketMultiplexerJob* job,
|
||||
bool read, bool write, bool error)
|
||||
{
|
||||
(void) read;
|
||||
|
||||
Lock lock(&getMutex());
|
||||
|
||||
int status = 0;
|
||||
@@ -755,25 +755,28 @@ SecureSocket::serviceConnect(ISocketMultiplexerJob* job,
|
||||
|
||||
// If status < 0, error happened
|
||||
if (status < 0) {
|
||||
return NULL;
|
||||
return {false, {}};
|
||||
}
|
||||
|
||||
// If status > 0, success
|
||||
if (status > 0) {
|
||||
sendEvent(m_events->forIDataSocket().secureConnected());
|
||||
return newJob();
|
||||
return {true, newJob()};
|
||||
}
|
||||
|
||||
// Retry case
|
||||
return new TSocketMultiplexerMethodJob<SecureSocket>(
|
||||
return {
|
||||
true,
|
||||
std::make_unique<TSocketMultiplexerMethodJob<SecureSocket>>(
|
||||
this, &SecureSocket::serviceConnect,
|
||||
getSocket(), isReadable(), isWritable());
|
||||
getSocket(), isReadable(), isWritable())
|
||||
};
|
||||
}
|
||||
|
||||
ISocketMultiplexerJob*
|
||||
SecureSocket::serviceAccept(ISocketMultiplexerJob* job,
|
||||
bool, bool write, bool error)
|
||||
MultiplexerJobStatus SecureSocket::serviceAccept(ISocketMultiplexerJob* job,
|
||||
bool read, bool write, bool error)
|
||||
{
|
||||
(void) read;
|
||||
Lock lock(&getMutex());
|
||||
|
||||
int status = 0;
|
||||
@@ -784,19 +787,19 @@ SecureSocket::serviceAccept(ISocketMultiplexerJob* job,
|
||||
#endif
|
||||
// If status < 0, error happened
|
||||
if (status < 0) {
|
||||
return NULL;
|
||||
return {false, {}};
|
||||
}
|
||||
|
||||
// If status > 0, success
|
||||
if (status > 0) {
|
||||
sendEvent(m_events->forClientListener().accepted());
|
||||
return newJob();
|
||||
return {true, newJob()};
|
||||
}
|
||||
|
||||
// Retry case
|
||||
return new TSocketMultiplexerMethodJob<SecureSocket>(
|
||||
return {true, std::make_unique<TSocketMultiplexerMethodJob<SecureSocket>>(
|
||||
this, &SecureSocket::serviceAccept,
|
||||
getSocket(), isReadable(), isWritable());
|
||||
getSocket(), isReadable(), isWritable())};
|
||||
}
|
||||
|
||||
void
|
||||
|
||||
Reference in New Issue
Block a user