Unverified Commit e8939664 authored by Dennis Jenkins's avatar Dennis Jenkins Committed by GitHub

Merge pull request #688 from hyperxor/small_code_cleanup_in_client

Small code cleanup in Client side
parents 0dee2f6c dcf3ce49
...@@ -202,9 +202,6 @@ private: ...@@ -202,9 +202,6 @@ private:
void handleWritableEntry(const Aio::FdSet::Entry &entry); void handleWritableEntry(const Aio::FdSet::Entry &entry);
void handleHangupEntry(const Aio::FdSet::Entry &entry); void handleHangupEntry(const Aio::FdSet::Entry &entry);
void handleIncoming(std::shared_ptr<Connection> connection); void handleIncoming(std::shared_ptr<Connection> connection);
void handleResponsePacket(const std::shared_ptr<Connection> &connection,
const char *buffer, size_t totalBytes);
void handleTimeout(const std::shared_ptr<Connection> &connection);
}; };
void Transport::onReady(const Aio::FdSet &fds) { void Transport::onReady(const Aio::FdSet &fds) {
...@@ -270,10 +267,9 @@ void Transport::asyncSendRequestImpl(const RequestEntry &req, ...@@ -270,10 +267,9 @@ void Transport::asyncSendRequestImpl(const RequestEntry &req,
ssize_t totalWritten = 0; ssize_t totalWritten = 0;
for (;;) { for (;;) {
ssize_t bytesWritten = 0; const char *data = buffer.data() + totalWritten;
ssize_t len = buffer.size() - totalWritten; const ssize_t len = buffer.size() - totalWritten;
auto ptr = buffer.data() + totalWritten; const ssize_t bytesWritten = ::send(fd, data, len, 0);
bytesWritten = ::send(fd, ptr, len, 0);
if (bytesWritten < 0) { if (bytesWritten < 0) {
if (errno == EAGAIN || errno == EWOULDBLOCK) { if (errno == EAGAIN || errno == EWOULDBLOCK) {
if (status == FirstTry) { if (status == FirstTry) {
...@@ -357,7 +353,7 @@ void Transport::handleReadableEntry(const Aio::FdSet::Entry &entry) { ...@@ -357,7 +353,7 @@ void Transport::handleReadableEntry(const Aio::FdSet::Entry &entry) {
if (timerIt != std::end(timeouts)) { if (timerIt != std::end(timeouts)) {
auto connection = timerIt->second.lock(); auto connection = timerIt->second.lock();
if (connection) { if (connection) {
handleTimeout(connection); connection->handleTimeout();
timeouts.erase(fd); timeouts.erase(fd);
} }
} }
...@@ -410,7 +406,7 @@ void Transport::handleIncoming(std::shared_ptr<Connection> connection) { ...@@ -410,7 +406,7 @@ void Transport::handleIncoming(std::shared_ptr<Connection> connection) {
if (bytes == -1) { if (bytes == -1) {
if (errno == EAGAIN || errno == EWOULDBLOCK) { if (errno == EAGAIN || errno == EWOULDBLOCK) {
if (totalBytes > 0) { if (totalBytes > 0) {
handleResponsePacket(connection, buffer, totalBytes); connection->handleResponsePacket(buffer, totalBytes);
} }
} else { } else {
connection->handleError(strerror(errno)); connection->handleError(strerror(errno));
...@@ -418,7 +414,7 @@ void Transport::handleIncoming(std::shared_ptr<Connection> connection) { ...@@ -418,7 +414,7 @@ void Transport::handleIncoming(std::shared_ptr<Connection> connection) {
break; break;
} else if (bytes == 0) { } else if (bytes == 0) {
if (totalBytes > 0) { if (totalBytes > 0) {
handleResponsePacket(connection, buffer, totalBytes); connection->handleResponsePacket(buffer, totalBytes);
} else { } else {
connection->handleError("Remote closed connection"); connection->handleError("Remote closed connection");
} }
...@@ -437,16 +433,6 @@ void Transport::handleIncoming(std::shared_ptr<Connection> connection) { ...@@ -437,16 +433,6 @@ void Transport::handleIncoming(std::shared_ptr<Connection> connection) {
} }
} }
void Transport::handleResponsePacket(
const std::shared_ptr<Connection> &connection, const char *buffer,
size_t totalBytes) {
connection->handleResponsePacket(buffer, totalBytes);
}
void Transport::handleTimeout(const std::shared_ptr<Connection> &connection) {
connection->handleTimeout();
}
Connection::Connection() : fd_(-1), requestEntry(nullptr) { Connection::Connection() : fd_(-1), requestEntry(nullptr) {
state_.store(static_cast<uint32_t>(State::Idle)); state_.store(static_cast<uint32_t>(State::Idle));
connectionState_.store(NotConnected); connectionState_.store(NotConnected);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment