mirror of
https://github.com/esp8266/Arduino.git
synced 2025-07-30 16:24:09 +03:00
Migrate from astyle to clang-format (#8464)
This commit is contained in:
committed by
Max Prokhorov
parent
46190b61f1
commit
19b7a29720
@ -44,26 +44,26 @@
|
||||
|
||||
// host socket internal side of WiFiServer
|
||||
|
||||
int serverAccept (int srvsock)
|
||||
int serverAccept(int srvsock)
|
||||
{
|
||||
int clisock;
|
||||
socklen_t n;
|
||||
struct sockaddr_in client;
|
||||
n = sizeof(client);
|
||||
if ((clisock = accept(srvsock, (struct sockaddr*)&client, &n)) == -1)
|
||||
{
|
||||
perror(MOCK "accept()");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
return mockSockSetup(clisock);
|
||||
int clisock;
|
||||
socklen_t n;
|
||||
struct sockaddr_in client;
|
||||
n = sizeof(client);
|
||||
if ((clisock = accept(srvsock, (struct sockaddr*)&client, &n)) == -1)
|
||||
{
|
||||
perror(MOCK "accept()");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
return mockSockSetup(clisock);
|
||||
}
|
||||
|
||||
void WiFiServer::begin (uint16_t port)
|
||||
void WiFiServer::begin(uint16_t port)
|
||||
{
|
||||
return begin(port, !0);
|
||||
}
|
||||
|
||||
void WiFiServer::begin (uint16_t port, uint8_t backlog)
|
||||
void WiFiServer::begin(uint16_t port, uint8_t backlog)
|
||||
{
|
||||
if (!backlog)
|
||||
return;
|
||||
@ -71,85 +71,86 @@ void WiFiServer::begin (uint16_t port, uint8_t backlog)
|
||||
return begin();
|
||||
}
|
||||
|
||||
void WiFiServer::begin ()
|
||||
void WiFiServer::begin()
|
||||
{
|
||||
int sock;
|
||||
int mockport;
|
||||
struct sockaddr_in server;
|
||||
int sock;
|
||||
int mockport;
|
||||
struct sockaddr_in server;
|
||||
|
||||
mockport = _port;
|
||||
if (mockport < 1024 && mock_port_shifter)
|
||||
{
|
||||
mockport += mock_port_shifter;
|
||||
fprintf(stderr, MOCK "=====> WiFiServer port: %d shifted to %d (use option -s) <=====\n", _port, mockport);
|
||||
}
|
||||
else
|
||||
fprintf(stderr, MOCK "=====> WiFiServer port: %d <=====\n", mockport);
|
||||
mockport = _port;
|
||||
if (mockport < 1024 && mock_port_shifter)
|
||||
{
|
||||
mockport += mock_port_shifter;
|
||||
fprintf(stderr, MOCK "=====> WiFiServer port: %d shifted to %d (use option -s) <=====\n",
|
||||
_port, mockport);
|
||||
}
|
||||
else
|
||||
fprintf(stderr, MOCK "=====> WiFiServer port: %d <=====\n", mockport);
|
||||
|
||||
if ((sock = socket(AF_INET, SOCK_STREAM, 0)) == -1)
|
||||
{
|
||||
perror(MOCK "socket()");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
if ((sock = socket(AF_INET, SOCK_STREAM, 0)) == -1)
|
||||
{
|
||||
perror(MOCK "socket()");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
int optval = 1;
|
||||
if (setsockopt(sock, SOL_SOCKET, SO_REUSEPORT, &optval, sizeof(optval)) == -1)
|
||||
{
|
||||
perror(MOCK "reuseport");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
int optval = 1;
|
||||
if (setsockopt(sock, SOL_SOCKET, SO_REUSEPORT, &optval, sizeof(optval)) == -1)
|
||||
{
|
||||
perror(MOCK "reuseport");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
server.sin_family = AF_INET;
|
||||
server.sin_port = htons(mockport);
|
||||
server.sin_addr.s_addr = htonl(global_source_address);
|
||||
if (bind(sock, (struct sockaddr*)&server, sizeof(server)) == -1)
|
||||
{
|
||||
perror(MOCK "bind()");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
server.sin_family = AF_INET;
|
||||
server.sin_port = htons(mockport);
|
||||
server.sin_addr.s_addr = htonl(global_source_address);
|
||||
if (bind(sock, (struct sockaddr*)&server, sizeof(server)) == -1)
|
||||
{
|
||||
perror(MOCK "bind()");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
if (listen(sock, 1) == -1)
|
||||
{
|
||||
perror(MOCK "listen()");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
if (listen(sock, 1) == -1)
|
||||
{
|
||||
perror(MOCK "listen()");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
|
||||
// store int into pointer
|
||||
_listen_pcb = int2pcb(sock);
|
||||
// store int into pointer
|
||||
_listen_pcb = int2pcb(sock);
|
||||
}
|
||||
|
||||
bool WiFiServer::hasClient ()
|
||||
bool WiFiServer::hasClient()
|
||||
{
|
||||
struct pollfd p;
|
||||
p.fd = pcb2int(_listen_pcb);
|
||||
p.events = POLLIN;
|
||||
return poll(&p, 1, 0) && p.revents == POLLIN;
|
||||
struct pollfd p;
|
||||
p.fd = pcb2int(_listen_pcb);
|
||||
p.events = POLLIN;
|
||||
return poll(&p, 1, 0) && p.revents == POLLIN;
|
||||
}
|
||||
|
||||
void WiFiServer::close ()
|
||||
void WiFiServer::close()
|
||||
{
|
||||
if (pcb2int(_listen_pcb) >= 0)
|
||||
::close(pcb2int(_listen_pcb));
|
||||
_listen_pcb = int2pcb(-1);
|
||||
if (pcb2int(_listen_pcb) >= 0)
|
||||
::close(pcb2int(_listen_pcb));
|
||||
_listen_pcb = int2pcb(-1);
|
||||
}
|
||||
|
||||
void WiFiServer::stop ()
|
||||
void WiFiServer::stop()
|
||||
{
|
||||
close();
|
||||
}
|
||||
|
||||
size_t WiFiServer::hasClientData ()
|
||||
size_t WiFiServer::hasClientData()
|
||||
{
|
||||
// Trivial Mocking:
|
||||
// There is no waiting list of clients in this trivial mocking code,
|
||||
// so the code has to act as if the tcp backlog list is full,
|
||||
// and nothing is known about potential further clients.
|
||||
// It could be implemented by accepting new clients and store their data until the current one is closed.
|
||||
// It could be implemented by accepting new clients and store their data until the current one
|
||||
// is closed.
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool WiFiServer::hasMaxPendingClients ()
|
||||
bool WiFiServer::hasMaxPendingClients()
|
||||
{
|
||||
// Mocking code does not consider the waiting client list,
|
||||
// so it will return ::hasClient() here meaning:
|
||||
|
Reference in New Issue
Block a user