void Port::Disconnect() {
IgnoreIOEvent();
+ std::lock_guard<std::recursive_mutex> lock(mutex_);
if (fd_ > 0) {
_W("Close fd(%d)", fd_);
close(fd_);
int bytes_read = 0;
char* buffer = static_cast<char*>(buf);
int max_timeout = MAX_CNT * MAX_SLEEP; /* 10 sec */
- std::lock_guard<std::recursive_mutex> lock(mutex_);
+ int fd;
- if (fd_ < 0 || fd_ >= sysconf(_SC_OPEN_MAX)) {
- _E("Invalid fd(%d)", fd_);
- return RPC_PORT_ERROR_IO_ERROR;
+ {
+ std::lock_guard<std::recursive_mutex> lock(mutex_);
+ fd = fd_;
+ if (fd < 0 || fd >= sysconf(_SC_OPEN_MAX)) {
+ _E("Invalid fd(%d)", fd);
+ return RPC_PORT_ERROR_IO_ERROR;
+ }
}
while (left) {
- nb = read(fd_, buffer, left);
+ {
+ std::lock_guard<std::recursive_mutex> lock(mutex_);
+ nb = read(fd, buffer, left);
+ }
+
if (nb == 0) {
- _E("read_socket: ...read EOF, socket closed %d: nb %zd\n", fd_, nb);
+ _E("read_socket: ...read EOF, socket closed %d: nb %zd\n", fd, nb);
return RPC_PORT_ERROR_IO_ERROR;
} else if (nb == -1) {
if (errno == EINTR || errno == EAGAIN || errno == EWOULDBLOCK) {
nanosleep(&TRY_SLEEP_TIME, 0);
max_timeout -= (TRY_SLEEP_TIME.tv_nsec / (BASE_SLEEP));
if (max_timeout <= 0) {
- _E("read_socket: ...timed out fd %d: errno %d", fd_, errno);
+ _E("read_socket: ...timed out fd %d: errno %d", fd, errno);
return RPC_PORT_ERROR_IO_ERROR;
}
TRY_SLEEP_TIME.tv_nsec *= 2;
continue;
}
- _E("read_socket: ...error fd %d: errno %d\n", fd_, errno);
+ _E("read_socket: ...error fd %d: errno %d\n", fd, errno);
return RPC_PORT_ERROR_IO_ERROR;
}