Fork of NetServicesMin with some warnings removed

Dependencies:   lwip-sys lwip

Fork of NetServicesMin by Hendrik Lipka

Committer:
uci1
Date:
Sat Nov 24 20:20:45 2012 +0000
Revision:
4:c8b2f969c8dd
Parent:
0:8b387bed54c2
Remove debugging printouts

Who changed what in which revision?

UserRevisionLine numberNew contents of line
hlipka 0:8b387bed54c2 1
hlipka 0:8b387bed54c2 2 /*
hlipka 0:8b387bed54c2 3 Copyright (c) 2010 Donatien Garnier (donatiengar [at] gmail [dot] com)
hlipka 0:8b387bed54c2 4
hlipka 0:8b387bed54c2 5 Permission is hereby granted, free of charge, to any person obtaining a copy
hlipka 0:8b387bed54c2 6 of this software and associated documentation files (the "Software"), to deal
hlipka 0:8b387bed54c2 7 in the Software without restriction, including without limitation the rights
hlipka 0:8b387bed54c2 8 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
hlipka 0:8b387bed54c2 9 copies of the Software, and to permit persons to whom the Software is
hlipka 0:8b387bed54c2 10 furnished to do so, subject to the following conditions:
hlipka 0:8b387bed54c2 11
hlipka 0:8b387bed54c2 12 The above copyright notice and this permission notice shall be included in
hlipka 0:8b387bed54c2 13 all copies or substantial portions of the Software.
hlipka 0:8b387bed54c2 14
hlipka 0:8b387bed54c2 15 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
hlipka 0:8b387bed54c2 16 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
hlipka 0:8b387bed54c2 17 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
hlipka 0:8b387bed54c2 18 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
hlipka 0:8b387bed54c2 19 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
hlipka 0:8b387bed54c2 20 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
hlipka 0:8b387bed54c2 21 THE SOFTWARE.
hlipka 0:8b387bed54c2 22 */
hlipka 0:8b387bed54c2 23
hlipka 0:8b387bed54c2 24 #ifndef LWIPNETTCPSOCKET_H
hlipka 0:8b387bed54c2 25 #define LWIPNETTCPSOCKET_H
hlipka 0:8b387bed54c2 26
hlipka 0:8b387bed54c2 27 #define NET_LWIP_STACK 1
hlipka 0:8b387bed54c2 28 #include "if/net/nettcpsocket.h"
hlipka 0:8b387bed54c2 29 #include "LwipNetIf.h"
hlipka 0:8b387bed54c2 30
hlipka 0:8b387bed54c2 31 #include "stdint.h"
hlipka 0:8b387bed54c2 32
hlipka 0:8b387bed54c2 33 //Implements NetTcpSockets over lwIP raw API
hlipka 0:8b387bed54c2 34
hlipka 0:8b387bed54c2 35 struct tcp_pcb; //Represents a Tcp Connection, "Protocol Control Block", see rawapi.txt & tcp.h
hlipka 0:8b387bed54c2 36 struct pbuf; //Lwip Buffer Container
hlipka 0:8b387bed54c2 37
hlipka 0:8b387bed54c2 38 typedef signed char err_t;
hlipka 0:8b387bed54c2 39 typedef uint16_t u16_t;
hlipka 0:8b387bed54c2 40
hlipka 0:8b387bed54c2 41 class LwipNetTcpSocket: public NetTcpSocket
hlipka 0:8b387bed54c2 42 {
hlipka 0:8b387bed54c2 43 public:
hlipka 0:8b387bed54c2 44 LwipNetTcpSocket(tcp_pcb* pPcb = NULL); //Passes a pcb if already created (by an accept req for instance), in that case transfers ownership
hlipka 0:8b387bed54c2 45 virtual ~LwipNetTcpSocket();
hlipka 0:8b387bed54c2 46
hlipka 0:8b387bed54c2 47 virtual NetTcpSocketErr bind(const Host& me);
hlipka 0:8b387bed54c2 48 virtual NetTcpSocketErr listen();
hlipka 0:8b387bed54c2 49 virtual NetTcpSocketErr connect(const Host& host);
hlipka 0:8b387bed54c2 50 virtual NetTcpSocketErr accept(Host* pClient, NetTcpSocket** ppNewNetTcpSocket);
hlipka 0:8b387bed54c2 51
hlipka 0:8b387bed54c2 52 virtual int /*if < 0 : NetTcpSocketErr*/ send(const char* buf, int len);
hlipka 0:8b387bed54c2 53 virtual int /*if < 0 : NetTcpSocketErr*/ recv(char* buf, int len);
hlipka 0:8b387bed54c2 54
hlipka 0:8b387bed54c2 55 virtual NetTcpSocketErr close();
hlipka 0:8b387bed54c2 56
hlipka 0:8b387bed54c2 57 virtual NetTcpSocketErr poll();
hlipka 0:8b387bed54c2 58
hlipka 0:8b387bed54c2 59 protected:
hlipka 0:8b387bed54c2 60 volatile tcp_pcb* m_pPcb;
hlipka 0:8b387bed54c2 61
hlipka 0:8b387bed54c2 62 //Events callbacks from lwIp
hlipka 0:8b387bed54c2 63 err_t acceptCb(tcp_pcb* newpcb, err_t err);
hlipka 0:8b387bed54c2 64 err_t connectedCb(tcp_pcb* tpcb, err_t err);
hlipka 0:8b387bed54c2 65
hlipka 0:8b387bed54c2 66 void errCb(err_t err);
hlipka 0:8b387bed54c2 67
hlipka 0:8b387bed54c2 68 err_t sentCb(tcp_pcb* tpcb, u16_t len);
hlipka 0:8b387bed54c2 69 err_t recvCb(tcp_pcb* tpcb, pbuf *p, err_t err);
hlipka 0:8b387bed54c2 70
hlipka 0:8b387bed54c2 71 private:
hlipka 0:8b387bed54c2 72 void cleanUp(); //Flush input buffer
hlipka 0:8b387bed54c2 73
hlipka 0:8b387bed54c2 74 // queue<tcp_pcb*> m_lpInPcb; //Incoming connections that have not been accepted yet
hlipka 0:8b387bed54c2 75 queue<LwipNetTcpSocket*> m_lpInNetTcpSocket; //Incoming connections that have not been accepted yet
hlipka 0:8b387bed54c2 76
hlipka 0:8b387bed54c2 77 volatile pbuf* m_pReadPbuf; //Ptr to read buffer
hlipka 0:8b387bed54c2 78
hlipka 0:8b387bed54c2 79 //Static callbacks : Transforms into a C++ callback
hlipka 0:8b387bed54c2 80 static err_t sAcceptCb(void *arg, struct tcp_pcb *newpcb, err_t err);
hlipka 0:8b387bed54c2 81 static err_t sConnectedCb(void *arg, struct tcp_pcb *tpcb, err_t err);
hlipka 0:8b387bed54c2 82
hlipka 0:8b387bed54c2 83 static void sErrCb(void *arg, err_t err);
hlipka 0:8b387bed54c2 84
hlipka 0:8b387bed54c2 85 static err_t sSentCb(void *arg, struct tcp_pcb *tpcb, u16_t len);
hlipka 0:8b387bed54c2 86 static err_t sRecvCb(void *arg, struct tcp_pcb *tpcb, struct pbuf *p, err_t err);
hlipka 0:8b387bed54c2 87
hlipka 0:8b387bed54c2 88 };
hlipka 0:8b387bed54c2 89
hlipka 0:8b387bed54c2 90 #endif