Skip to content
This repository was archived by the owner on Apr 16, 2018. It is now read-only.

Conversation

tkhurana96
Copy link
Contributor

No description provided.

@tkhurana96 tkhurana96 self-assigned this Feb 17, 2017
@tkhurana96 tkhurana96 requested a review from agauniyal February 17, 2017 16:35
namespace method {

inline std::string getErrorMsg()
inline std::string getErrorMsg(int errorNumber)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

const int errorNumber

src/socket.cpp Outdated

if (res == -1) {
throw std::runtime_error(net::method::getErrorMsg());
if (res == -1 && errno != EINPROGRESS ) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

take out errno and use that for checks, send that into net::method::getErrorMsg(errno) too.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, needs #include <errno.h> for errno - http://man7.org/linux/man-pages/man3/errno.3.html

src/socket.cpp Outdated
auto client = ::accept(sockfd, (sockaddr *) peerAddr.get(), &peerAddrSize);

if (client == -1) {
if (client == -1 && errno != EAGAIN && errno != EWOULDBLOCK) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here, take out errno into another var.

src/socket.cpp Outdated

if (client == -1) {
if (client == -1 && errno != EAGAIN && errno != EWOULDBLOCK) {
// TODO: Check for client == EAGAIN or EWOULDBLOCK and
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

delete these comments.

src/socket.cpp Outdated
const auto currentErrNo = errno;
errno = 0;
if (client == -1 && currentErrNo != EAGAIN && currentErrNo != EWOULDBLOCK) {
throw std::runtime_error(net::method::getErrorMsg(currentErrNo));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No way of finding out if non-blocking error.

src/socket.cpp Outdated
const auto currentErrNo = errno;
errno = 0;
if (written == -1 && currentErrNo != EAGAIN && currentErrNo != EWOULDBLOCK) {
throw std::runtime_error(net::method::getErrorMsg(currentErrNo));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No way of finding out if non-blocking error.

src/socket.cpp Outdated
const auto currentErrNo = errno;
errno = 0;
if (sent == -1 && currentErrNo != EAGAIN && currentErrNo != EWOULDBLOCK) {
throw std::runtime_error(net::method::getErrorMsg(currentErrNo));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No way of finding out if non-blocking error.

src/socket.cpp Outdated
const auto currentErrNo = errno;
errno = 0;
if (sent == -1 && currentErrNo != EAGAIN && currentErrNo != EWOULDBLOCK) {
throw std::runtime_error(net::method::getErrorMsg(currentErrNo));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No way of finding out if non-blocking error.

src/socket.cpp Outdated


std::string Socket::read(const int _bufSize) const
std::string Socket::read(const int _bufSize, bool *_isSpecialErrorInNonBlocking) const
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

parameter name quite big... _ErrorNB seems fine.

src/socket.cpp Outdated
throw std::runtime_error(net::method::getErrorMsg());
if ( !_isSpecialErrorInNonBlocking || (_isSpecialErrorInNonBlocking && currentErrNo != EAGAIN && currentErrNo != EWOULDBLOCK)) // blocking & non blocking failure case
throw std::runtime_error(net::method::getErrorMsg(currentErrNo));
// else if ( _isSpecialErrorInNonBlocking && currentErrNo != EAGAIN && currentErrNo != EWOULDBLOCK) // non blocking failure case
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove comments, use proper braces { } for if else statements.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

simplify logic, let compiler do the work.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does not throws invalid_argument in case nullptr is sent/or last param is ignored and non-blocking error occurs.

src/socket.cpp Outdated
// TODO: Check for bytes == EAGAIN or EWOULDBLOCK and
// don't throw exception in that case.
throw std::runtime_error(net::method::getErrorMsg());
if ( !_isSpecialErrorInNonBlocking || (_isSpecialErrorInNonBlocking && currentErrNo != EAGAIN && currentErrNo != EWOULDBLOCK)) // blocking & non blocking failure case
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

explicitly check for != nullptr instead of executing bool operator. Makes intent clear.

src/socket.cpp Outdated
// TODO: Check for recvd == EAGAIN or EWOULDBLOCK and
// don't throw exception in that case.
throw std::runtime_error(net::method::getErrorMsg());
if ( !_isSpecialErrorInNonBlocking || (_isSpecialErrorInNonBlocking && currentErrNo != EAGAIN && currentErrNo != EWOULDBLOCK))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here.

@agauniyal agauniyal merged commit f3d9d33 into feature/socket Feb 19, 2017
@agauniyal agauniyal deleted the errorHandling branch February 19, 2017 09:03
@agauniyal agauniyal added this to the 0.1 milestone Feb 23, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants