hattori&ide

Dependencies:   mbed

Committer:
hattori_atsushi
Date:
Sun Dec 18 08:16:01 2022 +0000
Revision:
0:f77369cabd75
hattori

Who changed what in which revision?

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