103 int fd = socket_->get_fd();
105 ESP_LOGW(TAG,
"Invalid socket fd");
112 FD_SET(fd, &writefds);
114 struct timeval tv = {0, 0};
115 int ret = select(fd + 1,
nullptr, &writefds,
nullptr, &tv);
117 if (ret > 0 && FD_ISSET(fd, &writefds)) {
120 if (socket_->getsockopt(SOL_SOCKET, SO_ERROR, &error, &
len) == 0 && error == 0) {
124 connect_cb_(connect_arg_,
this);
126 ESP_LOGW(TAG,
"Connection failed: %d", error);
129 error_cb_(error_arg_,
this, error);
131 }
else if (ret < 0) {
132 ESP_LOGE(TAG,
"Select error: %d", errno);
135 error_cb_(error_arg_,
this, errno);
137 }
else if (connected_) {
139 if (!socket_->ready())
142 uint8_t buf[READ_BUFFER_SIZE];
143 ssize_t len = socket_->read(buf, READ_BUFFER_SIZE);
146 ESP_LOGI(TAG,
"Connection closed by peer");
148 }
else if (
len > 0) {
150 data_cb_(data_arg_,
this, buf,
len);
151 }
else if (errno != EAGAIN && errno != EWOULDBLOCK) {
152 ESP_LOGW(TAG,
"Read error: %d", errno);
155 error_cb_(error_arg_,
this, errno);