aboutsummaryrefslogtreecommitdiff
path: root/libraries/Ethernet/Server.cpp
diff options
context:
space:
mode:
authorDavid A. Mellis <d.mellis@arduino.cc>2009-11-07 17:54:56 +0000
committerDavid A. Mellis <d.mellis@arduino.cc>2009-11-07 17:54:56 +0000
commit6005c59ad03446153c66a991f01ac91c31d98dac (patch)
tree4c599359fd35066a81b8b9fe99042e325c03c6ed /libraries/Ethernet/Server.cpp
parent584dece7b0c982de8731f7400c94b5034aef89e7 (diff)
Moving libraries out of arduino platform / core directory and to top-level.
Diffstat (limited to 'libraries/Ethernet/Server.cpp')
-rw-r--r--libraries/Ethernet/Server.cpp91
1 files changed, 0 insertions, 91 deletions
diff --git a/libraries/Ethernet/Server.cpp b/libraries/Ethernet/Server.cpp
deleted file mode 100644
index d17a5d3..0000000
--- a/libraries/Ethernet/Server.cpp
+++ /dev/null
@@ -1,91 +0,0 @@
-extern "C" {
- #include "types.h"
- #include "w5100.h"
- #include "socket.h"
- #include "string.h"
-}
-
-#include "Ethernet.h"
-#include "Client.h"
-#include "Server.h"
-
-Server::Server(uint16_t port)
-{
- _port = port;
-}
-
-void Server::begin()
-{
- for (int sock = 0; sock < MAX_SOCK_NUM; sock++) {
- Client client(sock);
- if (client.status() == SOCK_CLOSED) {
- socket(sock, Sn_MR_TCP, _port, 0);
- listen(sock);
- EthernetClass::_server_port[sock] = _port;
- break;
- }
- }
-}
-
-void Server::accept()
-{
- int listening = 0;
-
- for (int sock = 0; sock < MAX_SOCK_NUM; sock++) {
- Client client(sock);
-
- if (EthernetClass::_server_port[sock] == _port) {
- if (client.status() == SOCK_LISTEN) {
- listening = 1;
- } else if (client.status() == SOCK_CLOSE_WAIT && !client.available()) {
- client.stop();
- }
- }
- }
-
- if (!listening) {
- begin();
- }
-}
-
-Client Server::available()
-{
- accept();
-
- for (int sock = 0; sock < MAX_SOCK_NUM; sock++) {
- Client client(sock);
- if (EthernetClass::_server_port[sock] == _port &&
- client.status() == SOCK_ESTABLISHED) {
- if (client.available()) {
- // XXX: don't always pick the lowest numbered socket.
- return client;
- }
- }
- }
-
- return Client(255);
-}
-
-void Server::write(uint8_t b)
-{
- write(&b, 1);
-}
-
-void Server::write(const char *str)
-{
- write((const uint8_t *)str, strlen(str));
-}
-
-void Server::write(const uint8_t *buffer, size_t size)
-{
- accept();
-
- for (int sock = 0; sock < MAX_SOCK_NUM; sock++) {
- Client client(sock);
-
- if (EthernetClass::_server_port[sock] == _port &&
- client.status() == SOCK_ESTABLISHED) {
- client.write(buffer, size);
- }
- }
-}