@@ -28,11 +28,11 @@ int EthernetClient::connect(const char * host, uint16_t port)
2828 DNSClient dns; // Look up the host first
2929 IPAddress remote_addr;
3030
31- if (sockindex < MAX_SOCK_NUM) {
32- if (Ethernet.socketStatus (sockindex ) != SnSR::CLOSED) {
33- Ethernet.socketDisconnect (sockindex ); // TODO: should we call stop()?
31+ if (_sockindex < MAX_SOCK_NUM) {
32+ if (Ethernet.socketStatus (_sockindex ) != SnSR::CLOSED) {
33+ Ethernet.socketDisconnect (_sockindex ); // TODO: should we call stop()?
3434 }
35- sockindex = MAX_SOCK_NUM;
35+ _sockindex = MAX_SOCK_NUM;
3636 }
3737 dns.begin (Ethernet.dnsServerIP ());
3838 if (!dns.getHostByName (host, remote_addr)) return 0 ; // TODO: use _timeout
@@ -41,38 +41,38 @@ int EthernetClient::connect(const char * host, uint16_t port)
4141
4242int EthernetClient::connect (IPAddress ip, uint16_t port)
4343{
44- if (sockindex < MAX_SOCK_NUM) {
45- if (Ethernet.socketStatus (sockindex ) != SnSR::CLOSED) {
46- Ethernet.socketDisconnect (sockindex ); // TODO: should we call stop()?
44+ if (_sockindex < MAX_SOCK_NUM) {
45+ if (Ethernet.socketStatus (_sockindex ) != SnSR::CLOSED) {
46+ Ethernet.socketDisconnect (_sockindex ); // TODO: should we call stop()?
4747 }
48- sockindex = MAX_SOCK_NUM;
48+ _sockindex = MAX_SOCK_NUM;
4949 }
5050#if defined(ESP8266) || defined(ESP32)
5151 if (ip == IPAddress ((uint32_t )0 ) || ip == IPAddress (0xFFFFFFFFul )) return 0 ;
5252#else
5353 if (ip == IPAddress (0ul ) || ip == IPAddress (0xFFFFFFFFul )) return 0 ;
5454#endif
55- sockindex = Ethernet.socketBegin (SnMR::TCP, 0 );
56- if (sockindex >= MAX_SOCK_NUM) return 0 ;
57- Ethernet.socketConnect (sockindex , rawIPAddress (ip), port);
55+ _sockindex = Ethernet.socketBegin (SnMR::TCP, 0 );
56+ if (_sockindex >= MAX_SOCK_NUM) return 0 ;
57+ Ethernet.socketConnect (_sockindex , rawIPAddress (ip), port);
5858 uint32_t start = millis ();
5959 while (1 ) {
60- uint8_t stat = Ethernet.socketStatus (sockindex );
60+ uint8_t stat = Ethernet.socketStatus (_sockindex );
6161 if (stat == SnSR::ESTABLISHED) return 1 ;
6262 if (stat == SnSR::CLOSE_WAIT) return 1 ;
6363 if (stat == SnSR::CLOSED) return 0 ;
6464 if (millis () - start > _timeout) break ;
6565 delay (1 );
6666 }
67- Ethernet.socketClose (sockindex );
68- sockindex = MAX_SOCK_NUM;
67+ Ethernet.socketClose (_sockindex );
68+ _sockindex = MAX_SOCK_NUM;
6969 return 0 ;
7070}
7171
7272int EthernetClient::availableForWrite (void )
7373{
74- if (sockindex >= MAX_SOCK_NUM) return 0 ;
75- return Ethernet.socketSendAvailable (sockindex );
74+ if (_sockindex >= MAX_SOCK_NUM) return 0 ;
75+ return Ethernet.socketSendAvailable (_sockindex );
7676}
7777
7878size_t EthernetClient::write (uint8_t b)
@@ -82,16 +82,16 @@ size_t EthernetClient::write(uint8_t b)
8282
8383size_t EthernetClient::write (const uint8_t *buf, size_t size)
8484{
85- if (sockindex >= MAX_SOCK_NUM) return 0 ;
86- if (Ethernet.socketSend (sockindex , buf, size)) return size;
85+ if (_sockindex >= MAX_SOCK_NUM) return 0 ;
86+ if (Ethernet.socketSend (_sockindex , buf, size)) return size;
8787 setWriteError ();
8888 return 0 ;
8989}
9090
9191int EthernetClient::available ()
9292{
93- if (sockindex >= MAX_SOCK_NUM) return 0 ;
94- return Ethernet.socketRecvAvailable (sockindex );
93+ if (_sockindex >= MAX_SOCK_NUM) return 0 ;
94+ return Ethernet.socketRecvAvailable (_sockindex );
9595 // TODO: do the WIZnet chips automatically retransmit TCP ACK
9696 // packets if they are lost by the network? Someday this should
9797 // be checked by a man-in-the-middle test which discards certain
@@ -102,88 +102,88 @@ int EthernetClient::available()
102102
103103int EthernetClient::read (uint8_t *buf, size_t size)
104104{
105- if (sockindex >= MAX_SOCK_NUM) return 0 ;
106- return Ethernet.socketRecv (sockindex , buf, size);
105+ if (_sockindex >= MAX_SOCK_NUM) return 0 ;
106+ return Ethernet.socketRecv (_sockindex , buf, size);
107107}
108108
109109int EthernetClient::peek ()
110110{
111- if (sockindex >= MAX_SOCK_NUM) return -1 ;
111+ if (_sockindex >= MAX_SOCK_NUM) return -1 ;
112112 if (!available ()) return -1 ;
113- return Ethernet.socketPeek (sockindex );
113+ return Ethernet.socketPeek (_sockindex );
114114}
115115
116116int EthernetClient::read ()
117117{
118118 uint8_t b;
119- if (Ethernet.socketRecv (sockindex , &b, 1 ) > 0 ) return b;
119+ if (Ethernet.socketRecv (_sockindex , &b, 1 ) > 0 ) return b;
120120 return -1 ;
121121}
122122
123123void EthernetClient::flush ()
124124{
125- while (sockindex < MAX_SOCK_NUM) {
126- uint8_t stat = Ethernet.socketStatus (sockindex );
125+ while (_sockindex < MAX_SOCK_NUM) {
126+ uint8_t stat = Ethernet.socketStatus (_sockindex );
127127 if (stat != SnSR::ESTABLISHED && stat != SnSR::CLOSE_WAIT) return ;
128- if (Ethernet.socketSendAvailable (sockindex ) >= W5100.SSIZE ) return ;
128+ if (Ethernet.socketSendAvailable (_sockindex ) >= W5100.SSIZE ) return ;
129129 }
130130}
131131
132132void EthernetClient::stop ()
133133{
134- if (sockindex >= MAX_SOCK_NUM) return ;
134+ if (_sockindex >= MAX_SOCK_NUM) return ;
135135
136136 // attempt to close the connection gracefully (send a FIN to other side)
137- Ethernet.socketDisconnect (sockindex );
137+ Ethernet.socketDisconnect (_sockindex );
138138 unsigned long start = millis ();
139139
140140 // wait up to a second for the connection to close
141141 do {
142- if (Ethernet.socketStatus (sockindex ) == SnSR::CLOSED) {
143- sockindex = MAX_SOCK_NUM;
142+ if (Ethernet.socketStatus (_sockindex ) == SnSR::CLOSED) {
143+ _sockindex = MAX_SOCK_NUM;
144144 return ; // exit the loop
145145 }
146146 delay (1 );
147147 } while (millis () - start < _timeout);
148148
149149 // if it hasn't closed, close it forcefully
150- Ethernet.socketClose (sockindex );
151- sockindex = MAX_SOCK_NUM;
150+ Ethernet.socketClose (_sockindex );
151+ _sockindex = MAX_SOCK_NUM;
152152}
153153
154154uint8_t EthernetClient::connected ()
155155{
156- if (sockindex >= MAX_SOCK_NUM) return 0 ;
156+ if (_sockindex >= MAX_SOCK_NUM) return 0 ;
157157
158- uint8_t s = Ethernet.socketStatus (sockindex );
158+ uint8_t s = Ethernet.socketStatus (_sockindex );
159159 return !(s == SnSR::LISTEN || s == SnSR::CLOSED || s == SnSR::FIN_WAIT ||
160160 (s == SnSR::CLOSE_WAIT && !available ()));
161161}
162162
163163uint8_t EthernetClient::status ()
164164{
165- if (sockindex >= MAX_SOCK_NUM) return SnSR::CLOSED;
166- return Ethernet.socketStatus (sockindex );
165+ if (_sockindex >= MAX_SOCK_NUM) return SnSR::CLOSED;
166+ return Ethernet.socketStatus (_sockindex );
167167}
168168
169169// the next function allows us to use the client returned by
170170// EthernetServer::available() as the condition in an if-statement.
171171bool EthernetClient::operator ==(const EthernetClient& rhs)
172172{
173- if (sockindex != rhs.sockindex ) return false ;
174- if (sockindex >= MAX_SOCK_NUM) return false ;
175- if (rhs.sockindex >= MAX_SOCK_NUM) return false ;
173+ if (_sockindex != rhs._sockindex ) return false ;
174+ if (_sockindex >= MAX_SOCK_NUM) return false ;
175+ if (rhs._sockindex >= MAX_SOCK_NUM) return false ;
176176 return true ;
177177}
178178
179179// https://github.com/per1234/EthernetMod
180180// from: https://github.com/ntruchsess/Arduino-1/commit/937bce1a0bb2567f6d03b15df79525569377dabd
181181uint16_t EthernetClient::localPort ()
182182{
183- if (sockindex >= MAX_SOCK_NUM) return 0 ;
183+ if (_sockindex >= MAX_SOCK_NUM) return 0 ;
184184 uint16_t port;
185185 SPI.beginTransaction (SPI_ETHERNET_SETTINGS);
186- port = W5100.readSnPORT (sockindex );
186+ port = W5100.readSnPORT (_sockindex );
187187 SPI.endTransaction ();
188188 return port;
189189}
@@ -192,10 +192,10 @@ uint16_t EthernetClient::localPort()
192192// returns the remote IP address: https://forum.arduino.cc/index.php?topic=82416.0
193193IPAddress EthernetClient::remoteIP ()
194194{
195- if (sockindex >= MAX_SOCK_NUM) return IPAddress ((uint32_t )0 );
195+ if (_sockindex >= MAX_SOCK_NUM) return IPAddress ((uint32_t )0 );
196196 uint8_t remoteIParray[4 ];
197197 SPI.beginTransaction (SPI_ETHERNET_SETTINGS);
198- W5100.readSnDIPR (sockindex , remoteIParray);
198+ W5100.readSnDIPR (_sockindex , remoteIParray);
199199 SPI.endTransaction ();
200200 return IPAddress (remoteIParray);
201201}
@@ -204,10 +204,10 @@ IPAddress EthernetClient::remoteIP()
204204// from: https://github.com/ntruchsess/Arduino-1/commit/ca37de4ba4ecbdb941f14ac1fe7dd40f3008af75
205205uint16_t EthernetClient::remotePort ()
206206{
207- if (sockindex >= MAX_SOCK_NUM) return 0 ;
207+ if (_sockindex >= MAX_SOCK_NUM) return 0 ;
208208 uint16_t port;
209209 SPI.beginTransaction (SPI_ETHERNET_SETTINGS);
210- port = W5100.readSnDPORT (sockindex );
210+ port = W5100.readSnDPORT (_sockindex );
211211 SPI.endTransaction ();
212212 return port;
213213}
0 commit comments