vfv
Fork of WizFi310Interface_Legacynew by
Socket/Socket.cpp@4:4a014b170d40, 2018-02-01 (annotated)
- Committer:
- Dxmanas
- Date:
- Thu Feb 01 08:00:01 2018 +0000
- Revision:
- 4:4a014b170d40
- Parent:
- 0:774ff1e8b26b
commit
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
kaizen | 0:774ff1e8b26b | 1 | /* |
kaizen | 0:774ff1e8b26b | 2 | * Copyright (C) 2013 gsfan, MIT License |
kaizen | 0:774ff1e8b26b | 3 | * |
kaizen | 0:774ff1e8b26b | 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software |
kaizen | 0:774ff1e8b26b | 5 | * and associated documentation files (the "Software"), to deal in the Software without restriction, |
kaizen | 0:774ff1e8b26b | 6 | * including without limitation the rights to use, copy, modify, merge, publish, distribute, |
kaizen | 0:774ff1e8b26b | 7 | * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is |
kaizen | 0:774ff1e8b26b | 8 | * furnished to do so, subject to the following conditions: |
kaizen | 0:774ff1e8b26b | 9 | * |
kaizen | 0:774ff1e8b26b | 10 | * The above copyright notice and this permission notice shall be included in all copies or |
kaizen | 0:774ff1e8b26b | 11 | * substantial portions of the Software. |
kaizen | 0:774ff1e8b26b | 12 | * |
kaizen | 0:774ff1e8b26b | 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING |
kaizen | 0:774ff1e8b26b | 14 | * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
kaizen | 0:774ff1e8b26b | 15 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, |
kaizen | 0:774ff1e8b26b | 16 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
kaizen | 0:774ff1e8b26b | 17 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
kaizen | 0:774ff1e8b26b | 18 | */ |
kaizen | 0:774ff1e8b26b | 19 | /* Copyright (C) 2014 Wiznet, MIT License |
kaizen | 0:774ff1e8b26b | 20 | * port to the Wiznet Module WizFi250 |
kaizen | 0:774ff1e8b26b | 21 | */ |
kaizen | 0:774ff1e8b26b | 22 | /* Copyright (C) 2017 Wiznet, MIT License |
kaizen | 0:774ff1e8b26b | 23 | * port to the Wiznet Module WizFi310 |
kaizen | 0:774ff1e8b26b | 24 | */ |
kaizen | 0:774ff1e8b26b | 25 | |
kaizen | 0:774ff1e8b26b | 26 | #include "Socket.h" |
kaizen | 0:774ff1e8b26b | 27 | #include <cstring> |
kaizen | 0:774ff1e8b26b | 28 | |
kaizen | 0:774ff1e8b26b | 29 | Socket::Socket() { |
kaizen | 0:774ff1e8b26b | 30 | _wizfi310 = NULL; |
kaizen | 0:774ff1e8b26b | 31 | _wizfi310 = WizFi310::getInstance(); |
kaizen | 0:774ff1e8b26b | 32 | if (_wizfi310 == NULL) |
kaizen | 0:774ff1e8b26b | 33 | error("Socket constructor error: no WizFi250 instance available!\r\n"); |
kaizen | 0:774ff1e8b26b | 34 | _blocking = true; |
kaizen | 0:774ff1e8b26b | 35 | _timeout = 1500; |
kaizen | 0:774ff1e8b26b | 36 | |
kaizen | 0:774ff1e8b26b | 37 | _server = false; |
kaizen | 0:774ff1e8b26b | 38 | _cid = -1; |
kaizen | 0:774ff1e8b26b | 39 | _port = 0; |
kaizen | 0:774ff1e8b26b | 40 | } |
kaizen | 0:774ff1e8b26b | 41 | |
kaizen | 0:774ff1e8b26b | 42 | void Socket::set_blocking(bool blocking, unsigned int timeout) { |
kaizen | 0:774ff1e8b26b | 43 | _blocking = blocking; |
kaizen | 0:774ff1e8b26b | 44 | _timeout = timeout; |
kaizen | 0:774ff1e8b26b | 45 | } |
kaizen | 0:774ff1e8b26b | 46 | |
kaizen | 0:774ff1e8b26b | 47 | int Socket::close() { |
kaizen | 0:774ff1e8b26b | 48 | if (_cid < 0) return 0; |
kaizen | 0:774ff1e8b26b | 49 | |
kaizen | 0:774ff1e8b26b | 50 | _wizfi310->close(_cid); |
kaizen | 0:774ff1e8b26b | 51 | _cid = -1; |
kaizen | 0:774ff1e8b26b | 52 | return 0; |
kaizen | 0:774ff1e8b26b | 53 | } |
kaizen | 0:774ff1e8b26b | 54 | |
kaizen | 0:774ff1e8b26b | 55 | Socket::~Socket() { |
kaizen | 0:774ff1e8b26b | 56 | close(); //Don't want to leak |
kaizen | 0:774ff1e8b26b | 57 | } |