Brandon Fictorie / Mbed 2 deprecated BF_Websocket

Dependencies:   mbed

Committer:
bfictorie
Date:
Sun Mar 25 17:26:30 2012 +0000
Revision:
0:8cdad1c73e8e

        

Who changed what in which revision?

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