forked from jiahuang/CC3000
-
Notifications
You must be signed in to change notification settings - Fork 0
/
WiFiServer.cpp
61 lines (50 loc) · 1.03 KB
/
WiFiServer.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#include <string.h>
extern "C" {
#include "tm_debug.h"
}
#include "CC3000.h"
#include "WiFiClient.h"
#include "WiFiServer.h"
WiFiServer::WiFiServer(uint8_t sock, uint16_t port) : _sock(sock)
{
_port = port;
}
WiFiServer::WiFiServer(uint16_t port) : _sock(NO_SOCKET_AVAIL)
{
_port = port;
}
void WiFiServer::begin()
{
_sock = tm_net_tcp_open_socket();
if (_sock != NO_SOCKET_AVAIL) {
tm_net_tcp_listen(_sock, _port);
}
}
WiFiClient WiFiServer::available(byte* status)
{
sockaddr addrClient;
socklen_t addrLen;
int clientsock = tm_net_tcp_block_until_accepting(_sock, &addrClient, &addrLen);
delayMicroseconds(100);
// Negative client may imply closed socket.
if (clientsock < 0) {
_sock = tm_net_tcp_close_socket(_sock);
begin();
return available(status);
}
return WiFiClient(clientsock);
}
uint8_t WiFiServer::status()
{
// TODO
return 1;
}
size_t WiFiServer::write (uint8_t b)
{
return write(&b, 1);
}
size_t WiFiServer::write (const uint8_t *buffer, size_t size)
{
// TODO
return 0;
}