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: GSwifi_httpd GSwifi_websocket GSwifi_tcpclient GSwifi_tcpserver ... more
Fork of GSwifi by
Diff: GSwifi_sock.cpp
- Revision:
- 26:b347ee3a1087
- Parent:
- 25:f6e5622d2930
- Child:
- 28:fbba4c58d14c
diff -r f6e5622d2930 -r b347ee3a1087 GSwifi_sock.cpp
--- a/GSwifi_sock.cpp Mon Feb 11 06:01:46 2013 +0000
+++ b/GSwifi_sock.cpp Fri Feb 22 01:05:10 2013 +0000
@@ -25,7 +25,8 @@
#include "GSwifi.h"
-void GSwifi::newSock (int cid, GSTYPE type, GSPROTOCOL pro, onGsReceiveFunc ponGsReceive) {
+//void GSwifi::newSock (int cid, GSTYPE type, GSPROTOCOL pro, onGsReceiveFunc ponGsReceive) {
+void GSwifi::newSock (int cid, GSTYPE type, GSPROTOCOL pro) {
_gs_sock[cid].type = type;
_gs_sock[cid].protocol = pro;
_gs_sock[cid].connect = true;
@@ -35,8 +36,7 @@
_gs_sock[cid].data->flush();
}
_gs_sock[cid].lcid = 0;
- _gs_sock[cid].received = 0;
- _gs_sock[cid].onGsReceive = ponGsReceive;
+ _gs_sock[cid].received = false;
}
int GSwifi::open (Host &host, GSPROTOCOL pro, onGsReceiveFunc ponGsReceive) {
@@ -91,7 +91,6 @@
int GSwifi::send (int cid, const char *buf, int len) {
int i;
- Timer timeout;
if (! _gs_sock[cid].connect) return -1;
@@ -99,8 +98,7 @@
(_gs_sock[cid].protocol == GSPROT_UDP && _gs_sock[cid].type == GSTYPE_CLIENT) ||
(_gs_sock[cid].protocol == GSPROT_HTTPD)) {
// TCP Client, TCP Server, UDP Client
- _gs_ok = 0;
- _gs_failure = 0;
+ resetResponse(GSRES_NONE);
#ifdef GS_BULK
_gs.printf("\x1bZ%X%04d", cid, len);
for (i = 0; i < len; i ++) {
@@ -125,21 +123,18 @@
} else {
return -1;
}
- timeout.start();
- while (!_gs_ok && !_gs_failure && timeout.read_ms() < GS_TIMEOUT);
- return _gs_ok == 1 ? 0 : -1;
+
+ return waitResponse(GS_TIMEOUT);
}
int GSwifi::send (int cid, const char *buf, int len, Host &host) {
int i;
- Timer timeout;
if (! _gs_sock[cid].connect) return -1;
if ((_gs_sock[cid].protocol == GSPROT_UDP && _gs_sock[cid].type == GSTYPE_SERVER)) {
// UDP Server
- _gs_ok = 0;
- _gs_failure = 0;
+ resetResponse(GSRES_NONE);
#ifdef GS_BULK
_gs.printf("\x1bY%X", cid);
_gs.printf("%d.%d.%d.%d:%d:", host.getIp()[0], host.getIp()[1], host.getIp()[2], host.getIp()[3], host.getPort());
@@ -167,9 +162,8 @@
} else {
return -1;
}
- timeout.start();
- while (!_gs_ok && !_gs_failure && timeout.read_ms() < GS_TIMEOUT);
- return _gs_ok == 1 ? 0 : -1;
+
+ return waitResponse(GS_TIMEOUT);
}
int GSwifi::recv (int cid, char *buf, int len) {
@@ -179,7 +173,7 @@
if (_gs_sock[cid].data == NULL) return 0;
timeout.start();
- while (_gs_sock[cid].data->use() == 0) {
+ while (_gs_sock[cid].data->isEmpty()) {
if (timeout.read_ms() > GS_TIMEOUT) return 0;
}
timeout.stop();
@@ -197,7 +191,7 @@
if (_gs_sock[cid].data == NULL) return 0;
timeout.start();
- while (_gs_sock[cid].data->use() == 0) {
+ while (_gs_sock[cid].data->isEmpty()) {
if (timeout.read_ms() > GS_TIMEOUT) return 0;
}
timeout.stop();

GainSpan Wi-Fi GS1011