105 int fd = socket_->get_fd();
107 ESP_LOGW(TAG,
"Invalid socket fd");
114 FD_SET(fd, &writefds);
116 struct timeval tv = {0, 0};
117 int ret = select(fd + 1,
nullptr, &writefds,
nullptr, &tv);
119 if (ret > 0 && FD_ISSET(fd, &writefds)) {
122 if (socket_->getsockopt(SOL_SOCKET, SO_ERROR, &error, &
len) == 0 && error == 0) {
126 connect_cb_(connect_arg_,
this);
128 ESP_LOGW(TAG,
"Connection failed: %d", error);
131 error_cb_(error_arg_,
this, error);
133 }
else if (ret < 0) {
134 const int err = errno;
135 ESP_LOGE(TAG,
"Select error: %d", err);
138 error_cb_(error_arg_,
this, err);
140 }
else if (connected_) {
142 if (!socket_->ready())
145 uint8_t buf[READ_BUFFER_SIZE];
146 ssize_t len = socket_->read(buf, READ_BUFFER_SIZE);
149 ESP_LOGI(TAG,
"Connection closed by peer");
151 }
else if (
len > 0) {
153 data_cb_(data_arg_,
this, buf,
len);
155 const int err = errno;
156 if (err != EAGAIN && err != EWOULDBLOCK) {
157 ESP_LOGW(TAG,
"Read error: %d", err);
160 error_cb_(error_arg_,
this, err);