what is the return value of sockect close() function. I could not find in https://docs.espressif.com/projects/esp ... light=lwip.
I always get -1 as return of close(). I have SO_REUSEADDR enabled. Is it safe to reconnect use the same sock after I call close()? Would lwip reuse the sock I just close().
Thank you for any input.
here is the code i wrote:
Code: Select all
int tcp_socket_close(asl_socket_t *s)
{
int ret=0;
ret = shutdown(s->socketfd,SHUT_WR);//close write, send fin
if(ret<0)
{
ESP_LOGE(TAG, "tcp_socket_close:fail to SHUT_WR");
}
ret = shutdown(s->socketfd,SHUT_RD);//close read
if(ret<0)
{
ESP_LOGE(TAG, "tcp_socket_close:fail to SHUT_RD");
//return ret;
}
ret = close(s->socketfd);//destroy socket
ESP_LOGI(TAG, "tcp_socket_close: close() return:%d",ret);
return ret;
}
Code: Select all
int tcp_socket_reconnect(asl_socket_t *s)
{
int ret=0;
ret=tcp_socket_close(s);
// if(ret<0)
// {
// ESP_LOGI(TAG, "tcp_socket_reconnect:fail to close socket");
// //esp_restart();//fail to close the socket restart
// return ret;
// }
ret=tcp_socket_connect();
return ret;
}