mirror of
https://github.com/debauchee/barrier.git
synced 2026-11-27 22:32:02 +08:00
fixed misused read and write #4313
This commit is contained in:
@@ -467,7 +467,17 @@ TCPSocket::serviceConnected(ISocketMultiplexerJob* job,
|
||||
// write data
|
||||
UInt32 n = m_outputBuffer.getSize();
|
||||
const void* buffer = m_outputBuffer.peek(n);
|
||||
n = (UInt32)ARCH->writeSocket(m_socket, buffer, n);
|
||||
if (isSecure()) {
|
||||
if (isSecureReady()) {
|
||||
n = secureWrite(buffer, n);
|
||||
}
|
||||
else {
|
||||
return job;
|
||||
}
|
||||
}
|
||||
else {
|
||||
n = (UInt32)ARCH->writeSocket(m_socket, buffer, n);
|
||||
}
|
||||
|
||||
// discard written data
|
||||
if (n > 0) {
|
||||
@@ -510,14 +520,34 @@ TCPSocket::serviceConnected(ISocketMultiplexerJob* job,
|
||||
if (read && m_readable) {
|
||||
try {
|
||||
UInt8 buffer[4096];
|
||||
size_t n = ARCH->readSocket(m_socket, buffer, sizeof(buffer));
|
||||
size_t n = 0;
|
||||
|
||||
if (isSecure()) {
|
||||
if (isSecureReady()) {
|
||||
n = secureRead(buffer, sizeof(buffer));
|
||||
}
|
||||
else {
|
||||
return job;
|
||||
}
|
||||
}
|
||||
else {
|
||||
n = ARCH->readSocket(m_socket, buffer, sizeof(buffer));
|
||||
}
|
||||
|
||||
if (n > 0) {
|
||||
bool wasEmpty = (m_inputBuffer.getSize() == 0);
|
||||
|
||||
// slurp up as much as possible
|
||||
do {
|
||||
m_inputBuffer.write(buffer, (UInt32)n);
|
||||
n = ARCH->readSocket(m_socket, buffer, sizeof(buffer));
|
||||
|
||||
if (isSecure() && isSecureReady()) {
|
||||
n = secureRead(buffer, sizeof(buffer));
|
||||
}
|
||||
else {
|
||||
n = ARCH->readSocket(m_socket, buffer, sizeof(buffer));
|
||||
}
|
||||
|
||||
} while (n > 0);
|
||||
|
||||
// send input ready if input buffer was empty
|
||||
|
||||
@@ -57,19 +57,31 @@ public:
|
||||
// IDataSocket overrides
|
||||
virtual void connect(const NetworkAddress&);
|
||||
|
||||
virtual void secureConnect() {}
|
||||
virtual void secureAccept() {}
|
||||
|
||||
protected:
|
||||
virtual void onConnected();
|
||||
ArchSocket getSocket() { return m_socket; }
|
||||
|
||||
private:
|
||||
void init();
|
||||
virtual bool isSecureReady() { return false; }
|
||||
virtual bool isSecure() { return false; }
|
||||
virtual UInt32 secureRead(void* buffer, UInt32) { return 0; }
|
||||
virtual UInt32 secureWrite(const void*, UInt32) { return 0; }
|
||||
|
||||
void setJob(ISocketMultiplexerJob*);
|
||||
ISocketMultiplexerJob*
|
||||
newJob();
|
||||
bool isReadable() { return m_readable; }
|
||||
bool isWritable() { return m_writable; }
|
||||
|
||||
Mutex& getMutex() { return m_mutex; }
|
||||
|
||||
private:
|
||||
void init();
|
||||
|
||||
void sendConnectionFailedEvent(const char*);
|
||||
void sendEvent(Event::Type);
|
||||
|
||||
void onConnected();
|
||||
void onInputShutdown();
|
||||
void onOutputShutdown();
|
||||
void onDisconnected();
|
||||
|
||||
@@ -50,11 +50,9 @@ TCPSocketFactory::create(bool secure) const
|
||||
{
|
||||
IDataSocket* socket = NULL;
|
||||
if (secure) {
|
||||
void* args[4] = {
|
||||
void* args[2] = {
|
||||
m_events,
|
||||
m_socketMultiplexer,
|
||||
Log::getInstance(),
|
||||
Arch::getInstance()
|
||||
m_socketMultiplexer
|
||||
};
|
||||
socket = static_cast<IDataSocket*>(
|
||||
ARCH->plugin().invoke(s_networkSecurity, "getSecureSocket", args));
|
||||
@@ -71,11 +69,9 @@ TCPSocketFactory::createListen(bool secure) const
|
||||
{
|
||||
IListenSocket* socket = NULL;
|
||||
if (secure) {
|
||||
void* args[4] = {
|
||||
void* args[2] = {
|
||||
m_events,
|
||||
m_socketMultiplexer,
|
||||
Log::getInstance(),
|
||||
Arch::getInstance()
|
||||
m_socketMultiplexer
|
||||
};
|
||||
socket = static_cast<IListenSocket*>(
|
||||
ARCH->plugin().invoke(s_networkSecurity, "getSecureListenSocket", args));
|
||||
|
||||
Reference in New Issue
Block a user