Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Add setNoDelay and getNoDelay to WiFiServer class
  • Loading branch information
bbx10 committed May 19, 2017
commit 1f0af30d97634665458ae4e68fd41e3686d75709
15 changes: 13 additions & 2 deletions libraries/WiFi/src/WiFiServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,11 @@ WiFiClient WiFiServer::available(){
int client_sock = accept(sockfd, (struct sockaddr *)&_client, (socklen_t*)&cs);
if(client_sock >= 0){
int val = 1;
if(setsockopt(client_sock, SOL_SOCKET, SO_KEEPALIVE, (char*)&val, sizeof(int)) == ESP_OK)
return WiFiClient(client_sock);
if(setsockopt(client_sock, SOL_SOCKET, SO_KEEPALIVE, (char*)&val, sizeof(int)) == ESP_OK) {
val = _noDelay;
if(setsockopt(client_sock, IPPROTO_TCP, TCP_NODELAY, (char*)&val, sizeof(int)) == ESP_OK)
return WiFiClient(client_sock);
}
}
return WiFiClient();
}
Expand All @@ -69,6 +72,14 @@ void WiFiServer::begin(){
_listening = true;
}

void WiFiServer::setNoDelay(bool nodelay) {
_noDelay = nodelay;
}

bool WiFiServer::getNoDelay() {
return _noDelay;
}

void WiFiServer::end(){
close(sockfd);
sockfd = -1;
Expand Down
3 changes: 3 additions & 0 deletions libraries/WiFi/src/WiFiServer.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class WiFiServer : public Server {
uint16_t _port;
uint8_t _max_clients;
bool _listening;
bool _noDelay = false;

public:
void listenOnLocalhost(){}
Expand All @@ -38,6 +39,8 @@ class WiFiServer : public Server {
WiFiClient available();
WiFiClient accept(){return available();}
void begin();
void setNoDelay(bool nodelay);
bool getNoDelay();
size_t write(const uint8_t *data, size_t len);
size_t write(uint8_t data){
return write(&data, 1);
Expand Down