Experimental HTTPClient with proxy support

Committer:
igorsk
Date:
Wed Jun 29 16:01:58 2011 +0000
Revision:
0:b56b6a05cad4

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
igorsk 0:b56b6a05cad4 1
igorsk 0:b56b6a05cad4 2 /*
igorsk 0:b56b6a05cad4 3 Copyright (c) 2010 Donatien Garnier (donatiengar [at] gmail [dot] com)
igorsk 0:b56b6a05cad4 4
igorsk 0:b56b6a05cad4 5 Permission is hereby granted, free of charge, to any person obtaining a copy
igorsk 0:b56b6a05cad4 6 of this software and associated documentation files (the "Software"), to deal
igorsk 0:b56b6a05cad4 7 in the Software without restriction, including without limitation the rights
igorsk 0:b56b6a05cad4 8 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
igorsk 0:b56b6a05cad4 9 copies of the Software, and to permit persons to whom the Software is
igorsk 0:b56b6a05cad4 10 furnished to do so, subject to the following conditions:
igorsk 0:b56b6a05cad4 11
igorsk 0:b56b6a05cad4 12 The above copyright notice and this permission notice shall be included in
igorsk 0:b56b6a05cad4 13 all copies or substantial portions of the Software.
igorsk 0:b56b6a05cad4 14
igorsk 0:b56b6a05cad4 15 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
igorsk 0:b56b6a05cad4 16 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
igorsk 0:b56b6a05cad4 17 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
igorsk 0:b56b6a05cad4 18 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
igorsk 0:b56b6a05cad4 19 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
igorsk 0:b56b6a05cad4 20 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
igorsk 0:b56b6a05cad4 21 THE SOFTWARE.
igorsk 0:b56b6a05cad4 22 */
igorsk 0:b56b6a05cad4 23
igorsk 0:b56b6a05cad4 24 #ifndef NETUDPSOCKET_H
igorsk 0:b56b6a05cad4 25 #define NETUDPSOCKET_H
igorsk 0:b56b6a05cad4 26
igorsk 0:b56b6a05cad4 27 #include "net.h"
igorsk 0:b56b6a05cad4 28 #include "host.h"
igorsk 0:b56b6a05cad4 29
igorsk 0:b56b6a05cad4 30 #include <queue>
igorsk 0:b56b6a05cad4 31 using std::queue;
igorsk 0:b56b6a05cad4 32
igorsk 0:b56b6a05cad4 33 //Implements a Berkeley-like socket if
igorsk 0:b56b6a05cad4 34 //Can be interfaced either to lwip or a Telit module
igorsk 0:b56b6a05cad4 35
igorsk 0:b56b6a05cad4 36 enum NetUdpSocketErr
igorsk 0:b56b6a05cad4 37 {
igorsk 0:b56b6a05cad4 38 __NETUDPSOCKET_MIN = -0xFFFF,
igorsk 0:b56b6a05cad4 39 NETUDPSOCKET_SETUP, //NetUdpSocket not properly configured
igorsk 0:b56b6a05cad4 40 NETUDPSOCKET_IF, //If has problems
igorsk 0:b56b6a05cad4 41 NETUDPSOCKET_MEM, //Not enough mem
igorsk 0:b56b6a05cad4 42 NETUDPSOCKET_INUSE, //If/Port is in use
igorsk 0:b56b6a05cad4 43 //...
igorsk 0:b56b6a05cad4 44 NETUDPSOCKET_OK = 0
igorsk 0:b56b6a05cad4 45 };
igorsk 0:b56b6a05cad4 46
igorsk 0:b56b6a05cad4 47 enum NetUdpSocketEvent //Only one lonely event here... but who knows, maybe some day there'll be another one!
igorsk 0:b56b6a05cad4 48 {
igorsk 0:b56b6a05cad4 49 NETUDPSOCKET_READABLE, //Data in buf
igorsk 0:b56b6a05cad4 50 };
igorsk 0:b56b6a05cad4 51
igorsk 0:b56b6a05cad4 52
igorsk 0:b56b6a05cad4 53 class NetUdpSocket
igorsk 0:b56b6a05cad4 54 {
igorsk 0:b56b6a05cad4 55 public:
igorsk 0:b56b6a05cad4 56 NetUdpSocket();
igorsk 0:b56b6a05cad4 57 virtual ~NetUdpSocket(); //close()
igorsk 0:b56b6a05cad4 58
igorsk 0:b56b6a05cad4 59 virtual NetUdpSocketErr bind(const Host& me) = 0;
igorsk 0:b56b6a05cad4 60
igorsk 0:b56b6a05cad4 61 virtual int /*if < 0 : NetUdpSocketErr*/ sendto(const char* buf, int len, Host* pHost) = 0;
igorsk 0:b56b6a05cad4 62 virtual int /*if < 0 : NetUdpSocketErr*/ recvfrom(char* buf, int len, Host* pHost) = 0;
igorsk 0:b56b6a05cad4 63
igorsk 0:b56b6a05cad4 64 /* TODO NTH : printf / scanf helpers that call send/recv */
igorsk 0:b56b6a05cad4 65
igorsk 0:b56b6a05cad4 66 virtual NetUdpSocketErr close() = 0;
igorsk 0:b56b6a05cad4 67
igorsk 0:b56b6a05cad4 68 virtual NetUdpSocketErr poll() = 0;
igorsk 0:b56b6a05cad4 69
igorsk 0:b56b6a05cad4 70 class CDummy;
igorsk 0:b56b6a05cad4 71 //Callbacks
igorsk 0:b56b6a05cad4 72 template<class T>
igorsk 0:b56b6a05cad4 73 //Linker bug : Must be defined here :(
igorsk 0:b56b6a05cad4 74 void setOnEvent( T* pItem, void (T::*pMethod)(NetUdpSocketEvent) )
igorsk 0:b56b6a05cad4 75 {
igorsk 0:b56b6a05cad4 76 m_pCbItem = (CDummy*) pItem;
igorsk 0:b56b6a05cad4 77 m_pCbMeth = (void (CDummy::*)(NetUdpSocketEvent)) pMethod;
igorsk 0:b56b6a05cad4 78 }
igorsk 0:b56b6a05cad4 79
igorsk 0:b56b6a05cad4 80 void resetOnEvent(); //Disable callback
igorsk 0:b56b6a05cad4 81
igorsk 0:b56b6a05cad4 82 protected:
igorsk 0:b56b6a05cad4 83 void queueEvent(NetUdpSocketEvent e);
igorsk 0:b56b6a05cad4 84 void discardEvents();
igorsk 0:b56b6a05cad4 85 void flushEvents(); //to be called during polling
igorsk 0:b56b6a05cad4 86
igorsk 0:b56b6a05cad4 87 Host m_host;
igorsk 0:b56b6a05cad4 88 Host m_client;
igorsk 0:b56b6a05cad4 89
igorsk 0:b56b6a05cad4 90 friend class Net;
igorsk 0:b56b6a05cad4 91 int m_refs;
igorsk 0:b56b6a05cad4 92
igorsk 0:b56b6a05cad4 93 bool m_closed;
igorsk 0:b56b6a05cad4 94 bool m_removed;
igorsk 0:b56b6a05cad4 95
igorsk 0:b56b6a05cad4 96 private:
igorsk 0:b56b6a05cad4 97 //We do not want to execute user code in interrupt routines, so we queue events until the server is polled
igorsk 0:b56b6a05cad4 98 //If we port this to a multithreaded OS, we could avoid this (however some functions here are not thread-safe, so beware ;) )
igorsk 0:b56b6a05cad4 99 void onEvent(NetUdpSocketEvent e); //To be called on poll
igorsk 0:b56b6a05cad4 100 CDummy* m_pCbItem;
igorsk 0:b56b6a05cad4 101 void (CDummy::*m_pCbMeth)(NetUdpSocketEvent);
igorsk 0:b56b6a05cad4 102 queue<NetUdpSocketEvent> m_events;
igorsk 0:b56b6a05cad4 103
igorsk 0:b56b6a05cad4 104 };
igorsk 0:b56b6a05cad4 105
igorsk 0:b56b6a05cad4 106 #endif