Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: GSwifiInterface_HelloWorld GSwifiInterface_HelloServo GSwifiInterface_UDPEchoServer GSwifiInterface_UDPEchoClient ... more
Fork of WiflyInterface by
Socket/TCPSocketServer.cpp@21:6431364fc667, 2014-06-05 (annotated)
- Committer:
- gsfan
- Date:
- Thu Jun 05 06:12:59 2014 +0000
- Revision:
- 21:6431364fc667
- Parent:
- 11:71d67fea5ace
fix init (setAddress)
Who changed what in which revision?
| User | Revision | Line number | New contents of line | 
|---|---|---|---|
| gsfan | 5:78943b3945b5 | 1 | /* Copyright (C) 2012 mbed.org, MIT License | 
| gsfan | 5:78943b3945b5 | 2 | * | 
| gsfan | 5:78943b3945b5 | 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software | 
| gsfan | 5:78943b3945b5 | 4 | * and associated documentation files (the "Software"), to deal in the Software without restriction, | 
| gsfan | 5:78943b3945b5 | 5 | * including without limitation the rights to use, copy, modify, merge, publish, distribute, | 
| gsfan | 5:78943b3945b5 | 6 | * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is | 
| gsfan | 5:78943b3945b5 | 7 | * furnished to do so, subject to the following conditions: | 
| gsfan | 5:78943b3945b5 | 8 | * | 
| gsfan | 5:78943b3945b5 | 9 | * The above copyright notice and this permission notice shall be included in all copies or | 
| gsfan | 5:78943b3945b5 | 10 | * substantial portions of the Software. | 
| gsfan | 5:78943b3945b5 | 11 | * | 
| gsfan | 5:78943b3945b5 | 12 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING | 
| gsfan | 5:78943b3945b5 | 13 | * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | 
| gsfan | 5:78943b3945b5 | 14 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, | 
| gsfan | 5:78943b3945b5 | 15 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | 
| gsfan | 5:78943b3945b5 | 16 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | 
| gsfan | 5:78943b3945b5 | 17 | */ | 
| gsfan | 5:78943b3945b5 | 18 | /* Copyright (C) 2013 gsfan, MIT License | 
| gsfan | 5:78943b3945b5 | 19 | * port to the GainSpan Wi-FI module GS1011 | 
| gsfan | 5:78943b3945b5 | 20 | */ | 
| gsfan | 5:78943b3945b5 | 21 | |
| gsfan | 5:78943b3945b5 | 22 | #include "TCPSocketServer.h" | 
| gsfan | 5:78943b3945b5 | 23 | #include <string> | 
| gsfan | 5:78943b3945b5 | 24 | |
| gsfan | 5:78943b3945b5 | 25 | TCPSocketServer::TCPSocketServer() {} | 
| gsfan | 5:78943b3945b5 | 26 | |
| gsfan | 5:78943b3945b5 | 27 | // Server initialization | 
| gsfan | 5:78943b3945b5 | 28 | int TCPSocketServer::bind(int port) { | 
| gsfan | 5:78943b3945b5 | 29 | _port = port; | 
| gsfan | 5:78943b3945b5 | 30 | return 0; | 
| gsfan | 5:78943b3945b5 | 31 | } | 
| gsfan | 5:78943b3945b5 | 32 | |
| gsfan | 5:78943b3945b5 | 33 | int TCPSocketServer::listen(int backlog) { | 
| gsfan | 5:78943b3945b5 | 34 | _server = true; | 
| gsfan | 5:78943b3945b5 | 35 | if (_cid < 0) { | 
| gsfan | 5:78943b3945b5 | 36 | // Socket open | 
| gsfan | 5:78943b3945b5 | 37 | _server = false; | 
| gsfan | 8:64184a968e3b | 38 | _cid = _wifi->listen(GSwifi::PROTO_TCP, _port); | 
| gsfan | 8:64184a968e3b | 39 | if (_cid < 0) return -1; | 
| gsfan | 5:78943b3945b5 | 40 | } | 
| gsfan | 5:78943b3945b5 | 41 | |
| gsfan | 5:78943b3945b5 | 42 | if (backlog != 1) | 
| gsfan | 5:78943b3945b5 | 43 | return -1; | 
| gsfan | 5:78943b3945b5 | 44 | return 0; | 
| gsfan | 5:78943b3945b5 | 45 | } | 
| gsfan | 5:78943b3945b5 | 46 | |
| gsfan | 5:78943b3945b5 | 47 | |
| gsfan | 5:78943b3945b5 | 48 | int TCPSocketServer::accept(TCPSocketConnection& connection) { | 
| gsfan | 8:64184a968e3b | 49 | int acid = -1; | 
| gsfan | 5:78943b3945b5 | 50 | while (1) { | 
| gsfan | 8:64184a968e3b | 51 | while (acid < 0) { | 
| gsfan | 8:64184a968e3b | 52 | acid = _wifi->accept(_cid); | 
| gsfan | 8:64184a968e3b | 53 | } | 
| gsfan | 5:78943b3945b5 | 54 | if (acid >= 0) { | 
| gsfan | 8:64184a968e3b | 55 | connection.acceptCID(acid); | 
| gsfan | 5:78943b3945b5 | 56 | return 0; | 
| gsfan | 5:78943b3945b5 | 57 | } | 
| gsfan | 5:78943b3945b5 | 58 | } | 
| gsfan | 11:71d67fea5ace | 59 | return -1; | 
| samux | 1:fb4494783863 | 60 | } | 

 GainSpan Wi-Fi GS1011
            GainSpan Wi-Fi GS1011