11111

Dependents:   espyun1

Fork of WIZnetInterface by WIZnet

Committer:
jh_ndm
Date:
Fri Nov 04 02:28:28 2016 +0000
Revision:
30:6feeaebad180
Parent:
0:6f28332c466f
http to esp

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Soohwan Kim 0:6f28332c466f 1 /* Copyright (C) 2012 mbed.org, MIT License
Soohwan Kim 0:6f28332c466f 2 *
Soohwan Kim 0:6f28332c466f 3 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
Soohwan Kim 0:6f28332c466f 4 * and associated documentation files (the "Software"), to deal in the Software without restriction,
Soohwan Kim 0:6f28332c466f 5 * including without limitation the rights to use, copy, modify, merge, publish, distribute,
Soohwan Kim 0:6f28332c466f 6 * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
Soohwan Kim 0:6f28332c466f 7 * furnished to do so, subject to the following conditions:
Soohwan Kim 0:6f28332c466f 8 *
Soohwan Kim 0:6f28332c466f 9 * The above copyright notice and this permission notice shall be included in all copies or
Soohwan Kim 0:6f28332c466f 10 * substantial portions of the Software.
Soohwan Kim 0:6f28332c466f 11 *
Soohwan Kim 0:6f28332c466f 12 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
Soohwan Kim 0:6f28332c466f 13 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
Soohwan Kim 0:6f28332c466f 14 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
Soohwan Kim 0:6f28332c466f 15 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
Soohwan Kim 0:6f28332c466f 16 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Soohwan Kim 0:6f28332c466f 17 */
Soohwan Kim 0:6f28332c466f 18
Soohwan Kim 0:6f28332c466f 19 #include "Socket.h"
jh_ndm 30:6feeaebad180 20 //Serial pc(PA_13,PA_14);
Soohwan Kim 0:6f28332c466f 21 Socket::Socket() : _sock_fd(-1),_blocking(true), _timeout(1500)
Soohwan Kim 0:6f28332c466f 22 {
Soohwan Kim 0:6f28332c466f 23 eth = WIZnet_Chip::getInstance();
Soohwan Kim 0:6f28332c466f 24 if (eth == NULL) {
Soohwan Kim 0:6f28332c466f 25 error("Socket constructor error: no W7500 instance available!\r\n");
Soohwan Kim 0:6f28332c466f 26 }
Soohwan Kim 0:6f28332c466f 27 }
Soohwan Kim 0:6f28332c466f 28
Soohwan Kim 0:6f28332c466f 29 void Socket::set_blocking(bool blocking, unsigned int timeout)
Soohwan Kim 0:6f28332c466f 30 {
Soohwan Kim 0:6f28332c466f 31 _blocking = blocking;
Soohwan Kim 0:6f28332c466f 32 _timeout = timeout;
Soohwan Kim 0:6f28332c466f 33 }
Soohwan Kim 0:6f28332c466f 34
Soohwan Kim 0:6f28332c466f 35 int Socket::close()
Soohwan Kim 0:6f28332c466f 36 {
Soohwan Kim 0:6f28332c466f 37 // add this code refer from EthernetInterface.
Soohwan Kim 0:6f28332c466f 38 // update by Patrick Pollet
jh_ndm 30:6feeaebad180 39 //pc.printf("In Socket::close()\r\n");
Soohwan Kim 0:6f28332c466f 40 int res;
Soohwan Kim 0:6f28332c466f 41 res = eth->close(_sock_fd);
jh_ndm 30:6feeaebad180 42 //pc.printf("make _sock_fd = -1\r\n");
Soohwan Kim 0:6f28332c466f 43 _sock_fd = -1;
Soohwan Kim 0:6f28332c466f 44 return (res)? 0: -1;
Soohwan Kim 0:6f28332c466f 45 }
Soohwan Kim 0:6f28332c466f 46
Soohwan Kim 0:6f28332c466f 47 Socket::~Socket()
Soohwan Kim 0:6f28332c466f 48 {
Soohwan Kim 0:6f28332c466f 49 close(); //Don't want to leak
Soohwan Kim 0:6f28332c466f 50 }