Modified version of NetServices. Fixes an issue where connections failed should the HTTP response status line be received in a packet on its own prior to any further headers. Changes are made to the HTTPClient.cpp file's readHeaders method.

Committer:
andrewbonney
Date:
Fri Apr 08 14:39:41 2011 +0000
Revision:
0:ec559500a63f

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
andrewbonney 0:ec559500a63f 1
andrewbonney 0:ec559500a63f 2 /*
andrewbonney 0:ec559500a63f 3 Copyright (c) 2010 Donatien Garnier (donatiengar [at] gmail [dot] com)
andrewbonney 0:ec559500a63f 4
andrewbonney 0:ec559500a63f 5 Permission is hereby granted, free of charge, to any person obtaining a copy
andrewbonney 0:ec559500a63f 6 of this software and associated documentation files (the "Software"), to deal
andrewbonney 0:ec559500a63f 7 in the Software without restriction, including without limitation the rights
andrewbonney 0:ec559500a63f 8 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
andrewbonney 0:ec559500a63f 9 copies of the Software, and to permit persons to whom the Software is
andrewbonney 0:ec559500a63f 10 furnished to do so, subject to the following conditions:
andrewbonney 0:ec559500a63f 11
andrewbonney 0:ec559500a63f 12 The above copyright notice and this permission notice shall be included in
andrewbonney 0:ec559500a63f 13 all copies or substantial portions of the Software.
andrewbonney 0:ec559500a63f 14
andrewbonney 0:ec559500a63f 15 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
andrewbonney 0:ec559500a63f 16 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
andrewbonney 0:ec559500a63f 17 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
andrewbonney 0:ec559500a63f 18 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
andrewbonney 0:ec559500a63f 19 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
andrewbonney 0:ec559500a63f 20 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
andrewbonney 0:ec559500a63f 21 THE SOFTWARE.
andrewbonney 0:ec559500a63f 22 */
andrewbonney 0:ec559500a63f 23
andrewbonney 0:ec559500a63f 24 #ifndef USB_SERIAL_H
andrewbonney 0:ec559500a63f 25 #define USB_SERIAL_H
andrewbonney 0:ec559500a63f 26
andrewbonney 0:ec559500a63f 27 //DG 2010
andrewbonney 0:ec559500a63f 28 //Essentially a clone of Serial if
andrewbonney 0:ec559500a63f 29 #include "Stream.h"
andrewbonney 0:ec559500a63f 30 #include "mbed.h"
andrewbonney 0:ec559500a63f 31
andrewbonney 0:ec559500a63f 32 #include "drv/usb/UsbDevice.h"
andrewbonney 0:ec559500a63f 33 #include "drv/usb/UsbEndpoint.h"
andrewbonney 0:ec559500a63f 34
andrewbonney 0:ec559500a63f 35 namespace mbed {
andrewbonney 0:ec559500a63f 36
andrewbonney 0:ec559500a63f 37 class UsbSerial : public Stream {
andrewbonney 0:ec559500a63f 38
andrewbonney 0:ec559500a63f 39 public:
andrewbonney 0:ec559500a63f 40
andrewbonney 0:ec559500a63f 41 UsbSerial(UsbDevice* pDevice, int epIn, int epOut, const char* name = NULL);
andrewbonney 0:ec559500a63f 42 virtual ~UsbSerial();
andrewbonney 0:ec559500a63f 43 //Apart from the ctor/dtor, exactly the same protos as Serial
andrewbonney 0:ec559500a63f 44
andrewbonney 0:ec559500a63f 45 void baud(int baudrate);
andrewbonney 0:ec559500a63f 46
andrewbonney 0:ec559500a63f 47 enum Parity {
andrewbonney 0:ec559500a63f 48 None = 0,
andrewbonney 0:ec559500a63f 49 Odd = 1,
andrewbonney 0:ec559500a63f 50 Even = 2,
andrewbonney 0:ec559500a63f 51 Forced1 = 3,
andrewbonney 0:ec559500a63f 52 Forced0 = 4
andrewbonney 0:ec559500a63f 53 };
andrewbonney 0:ec559500a63f 54
andrewbonney 0:ec559500a63f 55 enum IrqType {
andrewbonney 0:ec559500a63f 56 RxIrq = 0
andrewbonney 0:ec559500a63f 57 , TxIrq
andrewbonney 0:ec559500a63f 58 };
andrewbonney 0:ec559500a63f 59
andrewbonney 0:ec559500a63f 60 void format(int bits, int parity, int stop);
andrewbonney 0:ec559500a63f 61
andrewbonney 0:ec559500a63f 62 class CDummy;
andrewbonney 0:ec559500a63f 63 template <class T>
andrewbonney 0:ec559500a63f 64 void attach(T* pCbItem, void (T::*pCbMeth)(), IrqType type = RxIrq)
andrewbonney 0:ec559500a63f 65 {
andrewbonney 0:ec559500a63f 66 if(type == RxIrq)
andrewbonney 0:ec559500a63f 67 {
andrewbonney 0:ec559500a63f 68 m_pInCbItem = (CDummy*) pCbItem;
andrewbonney 0:ec559500a63f 69 m_pInCbMeth = (void (CDummy::*)()) pCbMeth;
andrewbonney 0:ec559500a63f 70 }
andrewbonney 0:ec559500a63f 71 else
andrewbonney 0:ec559500a63f 72 {
andrewbonney 0:ec559500a63f 73 m_pOutCbItem = (CDummy*) pCbItem;
andrewbonney 0:ec559500a63f 74 m_pOutCbMeth = (void (CDummy::*)()) pCbMeth;
andrewbonney 0:ec559500a63f 75 }
andrewbonney 0:ec559500a63f 76 }
andrewbonney 0:ec559500a63f 77
andrewbonney 0:ec559500a63f 78 #if 0 // Inhereted from Stream, for documentation only
andrewbonney 0:ec559500a63f 79
andrewbonney 0:ec559500a63f 80 /* Function: putc
andrewbonney 0:ec559500a63f 81 * Write a character
andrewbonney 0:ec559500a63f 82 *
andrewbonney 0:ec559500a63f 83 * Variables:
andrewbonney 0:ec559500a63f 84 * c - The character to write to the serial port
andrewbonney 0:ec559500a63f 85 */
andrewbonney 0:ec559500a63f 86 int putc(int c);
andrewbonney 0:ec559500a63f 87
andrewbonney 0:ec559500a63f 88 /* Function: getc
andrewbonney 0:ec559500a63f 89 * Read a character
andrewbonney 0:ec559500a63f 90 *
andrewbonney 0:ec559500a63f 91 * Variables:
andrewbonney 0:ec559500a63f 92 * returns - The character read from the serial port
andrewbonney 0:ec559500a63f 93 */
andrewbonney 0:ec559500a63f 94 int getc();
andrewbonney 0:ec559500a63f 95
andrewbonney 0:ec559500a63f 96 /* Function: printf
andrewbonney 0:ec559500a63f 97 * Write a formated string
andrewbonney 0:ec559500a63f 98 *
andrewbonney 0:ec559500a63f 99 * Variables:
andrewbonney 0:ec559500a63f 100 * format - A printf-style format string, followed by the
andrewbonney 0:ec559500a63f 101 * variables to use in formating the string.
andrewbonney 0:ec559500a63f 102 */
andrewbonney 0:ec559500a63f 103 int printf(const char* format, ...);
andrewbonney 0:ec559500a63f 104
andrewbonney 0:ec559500a63f 105 /* Function: scanf
andrewbonney 0:ec559500a63f 106 * Read a formated string
andrewbonney 0:ec559500a63f 107 *
andrewbonney 0:ec559500a63f 108 * Variables:
andrewbonney 0:ec559500a63f 109 * format - A scanf-style format string,
andrewbonney 0:ec559500a63f 110 * followed by the pointers to variables to store the results.
andrewbonney 0:ec559500a63f 111 */
andrewbonney 0:ec559500a63f 112 int scanf(const char* format, ...);
andrewbonney 0:ec559500a63f 113
andrewbonney 0:ec559500a63f 114 #endif
andrewbonney 0:ec559500a63f 115
andrewbonney 0:ec559500a63f 116 /* Function: readable
andrewbonney 0:ec559500a63f 117 * Determine if there is a character available to read
andrewbonney 0:ec559500a63f 118 *
andrewbonney 0:ec559500a63f 119 * Variables:
andrewbonney 0:ec559500a63f 120 * returns - 1 if there is a character available to read, else 0
andrewbonney 0:ec559500a63f 121 */
andrewbonney 0:ec559500a63f 122 int readable();
andrewbonney 0:ec559500a63f 123
andrewbonney 0:ec559500a63f 124 /* Function: writeable
andrewbonney 0:ec559500a63f 125 * Determine if there is space available to write a character
andrewbonney 0:ec559500a63f 126 *
andrewbonney 0:ec559500a63f 127 * Variables:
andrewbonney 0:ec559500a63f 128 * returns - 1 if there is space to write a character, else 0
andrewbonney 0:ec559500a63f 129 */
andrewbonney 0:ec559500a63f 130 int writeable();
andrewbonney 0:ec559500a63f 131
andrewbonney 0:ec559500a63f 132 #ifdef MBED_RPC
andrewbonney 0:ec559500a63f 133 virtual const struct rpc_method *get_rpc_methods();
andrewbonney 0:ec559500a63f 134 static struct rpc_class *get_rpc_class();
andrewbonney 0:ec559500a63f 135 #endif
andrewbonney 0:ec559500a63f 136
andrewbonney 0:ec559500a63f 137 protected:
andrewbonney 0:ec559500a63f 138
andrewbonney 0:ec559500a63f 139 virtual int _getc();
andrewbonney 0:ec559500a63f 140 virtual int _putc(int c);
andrewbonney 0:ec559500a63f 141
andrewbonney 0:ec559500a63f 142 void onReadable();
andrewbonney 0:ec559500a63f 143 void onWriteable();
andrewbonney 0:ec559500a63f 144
andrewbonney 0:ec559500a63f 145 void onEpInTransfer();
andrewbonney 0:ec559500a63f 146 void onEpOutTransfer();
andrewbonney 0:ec559500a63f 147
andrewbonney 0:ec559500a63f 148 private:
andrewbonney 0:ec559500a63f 149
andrewbonney 0:ec559500a63f 150 UsbEndpoint m_epIn;
andrewbonney 0:ec559500a63f 151 UsbEndpoint m_epOut;
andrewbonney 0:ec559500a63f 152
andrewbonney 0:ec559500a63f 153 CDummy* m_pInCbItem;
andrewbonney 0:ec559500a63f 154 void (CDummy::*m_pInCbMeth)();
andrewbonney 0:ec559500a63f 155
andrewbonney 0:ec559500a63f 156 CDummy* m_pOutCbItem;
andrewbonney 0:ec559500a63f 157 void (CDummy::*m_pOutCbMeth)();
andrewbonney 0:ec559500a63f 158
andrewbonney 0:ec559500a63f 159 void startTx();
andrewbonney 0:ec559500a63f 160 void startRx();
andrewbonney 0:ec559500a63f 161
andrewbonney 0:ec559500a63f 162 Timeout m_txTimeout;
andrewbonney 0:ec559500a63f 163 volatile bool m_timeout;
andrewbonney 0:ec559500a63f 164
andrewbonney 0:ec559500a63f 165 volatile char* m_inBufEven;
andrewbonney 0:ec559500a63f 166 volatile char* m_inBufOdd;
andrewbonney 0:ec559500a63f 167 volatile char* m_inBufUsr;
andrewbonney 0:ec559500a63f 168 volatile char* m_inBufTrmt;
andrewbonney 0:ec559500a63f 169
andrewbonney 0:ec559500a63f 170 volatile char* m_outBufEven;
andrewbonney 0:ec559500a63f 171 volatile char* m_outBufOdd;
andrewbonney 0:ec559500a63f 172 volatile char* m_outBufUsr;
andrewbonney 0:ec559500a63f 173 volatile char* m_outBufTrmt;
andrewbonney 0:ec559500a63f 174
andrewbonney 0:ec559500a63f 175 volatile int m_inBufLen;
andrewbonney 0:ec559500a63f 176 volatile int m_outBufLen;
andrewbonney 0:ec559500a63f 177
andrewbonney 0:ec559500a63f 178 volatile char* m_pInBufPos;
andrewbonney 0:ec559500a63f 179 volatile char* m_pOutBufPos;
andrewbonney 0:ec559500a63f 180
andrewbonney 0:ec559500a63f 181
andrewbonney 0:ec559500a63f 182
andrewbonney 0:ec559500a63f 183 };
andrewbonney 0:ec559500a63f 184
andrewbonney 0:ec559500a63f 185 }
andrewbonney 0:ec559500a63f 186
andrewbonney 0:ec559500a63f 187
andrewbonney 0:ec559500a63f 188
andrewbonney 0:ec559500a63f 189 #endif