1
0
mirror of https://github.com/arduino/Arduino.git synced 2024-12-02 13:24:12 +01:00
Arduino/WiFi/WiFiServer.cpp

70 lines
1.4 KiB
C++
Raw Normal View History

2011-02-28 13:49:08 +01:00
#include <string.h>
#include "server_drv.h"
#include "WiFi.h"
#include "WiFiClient.h"
#include "WiFiServer.h"
2011-02-28 13:49:08 +01:00
WiFiServer::WiFiServer(uint16_t port)
2011-02-28 13:49:08 +01:00
{
_port = port;
}
void WiFiServer::begin()
2011-02-28 13:49:08 +01:00
{
uint8_t _sock = WiFiClass::getSocket();
if (_sock != NO_SOCKET_AVAIL)
{
ServerDrv::StartServer(_port, _sock);
WiFiClass::_server_port[_sock] = _port;
}
}
WiFiClient WiFiServer::available(byte* status)
2011-02-28 13:49:08 +01:00
{
//accept();
for (int sock = 0; sock < MAX_SOCK_NUM; sock++)
{
if (WiFiClass::_server_port[sock] != 0)
{
WiFiClient client(sock);
2011-04-21 19:16:39 +02:00
int _status = client.status();
if (status != NULL)
*status = _status;
2011-02-28 13:49:08 +01:00
if (WiFiClass::_server_port[sock] == _port &&
2011-04-21 19:16:39 +02:00
_status == ESTABLISHED)
2011-02-28 13:49:08 +01:00
{
return client; //TODO
}
}
}
return WiFiClient(255);
2011-02-28 13:49:08 +01:00
}
void WiFiServer::write(uint8_t b)
2011-02-28 13:49:08 +01:00
{
write(&b, 1);
}
void WiFiServer::write(const uint8_t *buffer, size_t size)
2011-02-28 13:49:08 +01:00
{
for (int sock = 0; sock < MAX_SOCK_NUM; sock++)
{
if (WiFiClass::_server_port[sock] != 0)
{
WiFiClient client(sock);
2011-02-28 13:49:08 +01:00
if (WiFiClass::_server_port[sock] == _port &&
client.status() == ESTABLISHED)
{
client.write(buffer, size);
}
}
}
}