GainSpan Wi-Fi library see: http://mbed.org/users/gsfan/notebook/gainspan_wifi/
Dependents: GSwifi_httpd GSwifi_websocket GSwifi_tcpclient GSwifi_tcpserver ... more
Fork of GSwifi by
GainSpan Wi-Fi library
The GS1011 is an ultra low power 802.11b wireless module from GainSpan.
see: http://mbed.org/users/gsfan/notebook/gainspan_wifi/
ゲインスパン Wi-Fi モジュール ライブラリ
ゲインスパン社の低電力 Wi-Fiモジュール(無線LAN) GS1011 シリーズ用のライブラリです。
解説: http://mbed.org/users/gsfan/notebook/gainspan_wifi/
Diff: GSwifi.cpp
- Revision:
- 25:f6e5622d2930
- Parent:
- 24:5c350ae2e703
- Child:
- 26:b347ee3a1087
--- a/GSwifi.cpp Wed Jan 23 07:41:23 2013 +0000 +++ b/GSwifi.cpp Mon Feb 11 06:01:46 2013 +0000 @@ -1,49 +1,57 @@ -/** - * Gainspan wi-fi module library for mbed - * Copyright (c) 2012 gsfan - * Released under the MIT License: http://mbed.org/license/mit +/* Copyright (C) 2013 gsfan, MIT License + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of this software + * and associated documentation files (the "Software"), to deal in the Software without restriction, + * including without limitation the rights to use, copy, modify, merge, publish, distribute, + * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies or + * substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING + * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ - /** @file * @brief Gainspan wi-fi module library for mbed * GS1011MIC, GS1011MIP, GainSpan WiFi Breakout, etc. - * module configuration: ATB=115200 */ #include "dbg.h" #include "mbed.h" #include "GSwifi.h" -#include <ctype.h> -GSwifi::GSwifi (PinName p_tx, PinName p_rx, int baud) : _gs(p_tx, p_rx), _buf_cmd(GS_CMD_SIZE) { - _connect = false; - _status = GSSTAT_READY; - _escape = 0; - _response = GSRES_NONE; - _gs_mode = GSMODE_COMMAND; - _ssid = NULL; - _reconnect = 0; - _reconnect_count = 0; +GSwifi::GSwifi (PinName p_tx, PinName p_rx, PinName p_reset, PinName p_alarm, int baud) : _gs(p_tx, p_rx), _reset(p_reset), _buf_cmd(GS_CMD_SIZE) { + + if (p_alarm != NC) { + _alarm = new DigitalOut(p_alarm); + _alarm->write(1); + } else { + _alarm = NULL; + } _gs.baud(baud); _gs.attach(this, &GSwifi::isr_recv, Serial::RxIrq); _rts = false; + + reset(); } -GSwifi::GSwifi (PinName p_tx, PinName p_rx, PinName p_cts, PinName p_rts, int baud) : _gs(p_tx, p_rx), _buf_cmd(GS_CMD_SIZE) { - _connect = false; - _status = GSSTAT_READY; - _escape = 0; - _response = GSRES_NONE; - _gs_mode = GSMODE_COMMAND; - _ssid = NULL; - _reconnect = 0; - _reconnect_count = 0; +GSwifi::GSwifi (PinName p_tx, PinName p_rx, PinName p_cts, PinName p_rts, PinName p_reset, PinName p_alarm, int baud) : _gs(p_tx, p_rx), _reset(p_reset), _buf_cmd(GS_CMD_SIZE) { + + if (p_alarm != NC) { + _alarm = new DigitalOut(p_alarm); + _alarm->write(1); + } else { + _alarm = NULL; + } _gs.baud(baud); _gs.attach(this, &GSwifi::isr_recv, Serial::RxIrq); - #if defined(TARGET_LPC1768) || defined(TARGET_LPC2368) if (p_cts == p12) { // CTS input (P0_17) LPC_UART1->MCR |= (1<<7); // CTSEN @@ -73,6 +81,24 @@ _rts = false; } #endif + + reset(); +} + +void GSwifi::reset () { + _connect = false; + _status = GSSTAT_READY; + _escape = 0; + _response = GSRES_NONE; + _gs_mode = GSMODE_COMMAND; + _ssid = NULL; + _reconnect = 0; + _reconnect_count = 0; + + _reset = 0; + wait_ms(100); + _reset = 1; + wait_ms(500); } // uart interrupt @@ -90,15 +116,9 @@ if (flg & ((1 << 7)|(1 << 3)|(1 << 4))) return; #ifdef DEBUG_VIEW -// DBG("%02x_", dat); + DBG("_%02x", dat); #endif -/* - if (dat >= 0x20 && dat < 0x7f) { - DBG("_%c", dat); - } else { - DBG("_%02x", dat); - } -*/ + switch (_gs_mode) { case GSMODE_COMMAND: // command responce if (_escape) { @@ -144,7 +164,7 @@ } else if (dat != '\r') { // command - _buf_cmd.put(dat); + _buf_cmd.queue(dat); if (dat == '\n') { _gs_enter ++; if (_response == GSRES_NONE && _connect) { @@ -217,7 +237,7 @@ _escape = 1; } else { // data - _gs_sock[_cid].data->put(dat); + _gs_sock[_cid].data->queue(dat); len ++; if (len < GS_DATA_SIZE && _gs_sock[_cid].data->available() == 0) { // buffer full @@ -231,7 +251,6 @@ case GSMODE_DATA_RX_BULK: case GSMODE_DATA_RXUDP_BULK: -// DBG("%c", dat); if (mode == 0) { // cid _cid = x2i(dat); @@ -282,7 +301,7 @@ if (mode == 4) { // data if (_gs_sock[_cid].data != NULL) { - _gs_sock[_cid].data->put(dat); + _gs_sock[_cid].data->queue(dat); } len --; if (len && _gs_sock[_cid].data->available() == 0) { @@ -317,13 +336,13 @@ for (i = 0; i < 10; i ++) { wait_ms(10); poll_cmd(); - _buf_cmd.clear(); + _buf_cmd.flush(); } return 0; } _response = res; - _buf_cmd.clear(); + _buf_cmd.flush(); _gs_ok = 0; _gs_failure = 0; _gs_enter = 0; @@ -352,8 +371,8 @@ // recv response i = 0; while (i < sizeof(buf)) { - if (_buf_cmd.use()) { - _buf_cmd.get(&buf[i]); + if (! _buf_cmd.isEmpty()) { + _buf_cmd.dequeue(&buf[i]); if (buf[i] == '\n') { break; } @@ -499,7 +518,6 @@ #endif disconnect(); - command("AT+WREGDOMAIN=" GS_WREGDOMAIN, GSRES_NORMAL); command("AT+WM=0", GSRES_NORMAL); // infrastructure wait_ms(100); if (dhcp && sec != GSSEC_WPS_BUTTON) { @@ -589,7 +607,6 @@ command("AT+BDATA=1", GSRES_NORMAL); #endif - command("AT+WREGDOMAIN=" GS_WREGDOMAIN, GSRES_NORMAL); command("AT+WM=1", GSRES_NORMAL); // adhock wait_ms(100); command("AT+NDHCP=0", GSRES_NORMAL); @@ -637,7 +654,6 @@ command("AT+BDATA=1", GSRES_NORMAL); #endif - command("AT+WREGDOMAIN=" GS_WREGDOMAIN, GSRES_NORMAL); command("AT+WM=2", GSRES_NORMAL); // limited ap wait_ms(1000); command("AT+NDHCP=0", GSRES_NORMAL); @@ -794,6 +810,17 @@ int GSwifi::wakeup () { + if (_status == GSSTAT_STANDBY && _alarm) { + Timer timeout; + _alarm->write(0); + timeout.start(); + while (_status != GSSTAT_WAKEUP && timeout.read() < GS_TIMEOUT) { + poll(); + } + timeout.stop(); + _alarm->write(1); + } + if (_status == GSSTAT_WAKEUP) { _status = GSSTAT_READY; command("ATE0", GSRES_NORMAL); @@ -827,7 +854,7 @@ return _connect; } -GSSTATUS GSwifi::getStatus () { +GSwifi::GSSTATUS GSwifi::getStatus () { return _status; } @@ -897,8 +924,8 @@ // wait_ms(10); _gs_enter --; i = 0; - while (_buf_cmd.use() && i < sizeof(buf)) { - _buf_cmd.get(&buf[i]); + while ((! _buf_cmd.isEmpty()) && i < sizeof(buf)) { + _buf_cmd.dequeue(&buf[i]); if (buf[i] == '\n') { break; } @@ -1016,299 +1043,6 @@ } } -void GSwifi::newSock (int cid, GSTYPE type, GSPROTOCOL pro, onGsReceiveFunc ponGsReceive) { - _gs_sock[cid].type = type; - _gs_sock[cid].protocol = pro; - _gs_sock[cid].connect = true; - if (_gs_sock[cid].data == NULL) { - _gs_sock[cid].data = new RingBuffer(GS_DATA_SIZE); - } else { - _gs_sock[cid].data->clear(); - } - _gs_sock[cid].lcid = 0; - _gs_sock[cid].received = 0; - _gs_sock[cid].onGsReceive = ponGsReceive; -} - -int GSwifi::open (Host &host, GSPROTOCOL pro, onGsReceiveFunc ponGsReceive) { - char cmd[GS_CMD_SIZE]; - - if (! _connect || _status != GSSTAT_READY) return -1; - if (host.getIp().isNull() || host.getPort() == 0) { - return -1; - } - - if (pro == GSPROT_UDP) { - sprintf(cmd, "AT+NCUDP=%d.%d.%d.%d,%d", host.getIp()[0], host.getIp()[1], host.getIp()[2], host.getIp()[3], host.getPort()); - } else { - sprintf(cmd, "AT+NCTCP=%d.%d.%d.%d,%d", host.getIp()[0], host.getIp()[1], host.getIp()[2], host.getIp()[3], host.getPort()); - } - if (command(cmd, GSRES_CONNECT)) return -1; - - newSock(_cid, GSTYPE_CLIENT, pro, ponGsReceive); - return _cid; -} - -int GSwifi::listen (int port, GSPROTOCOL pro, onGsReceiveFunc ponGsReceive) { - char cmd[GS_CMD_SIZE]; - - if (! _connect || _status != GSSTAT_READY) return -1; - if (port == 0) { - return -1; - } - - if (pro == GSPROT_UDP) { - sprintf(cmd, "AT+NSUDP=%d", port); - } else { - sprintf(cmd, "AT+NSTCP=%d", port); - } - if (command(cmd, GSRES_CONNECT)) return -1; - - newSock(_cid, GSTYPE_SERVER, pro, ponGsReceive); - return _cid; -} - -int GSwifi::close (int cid) { - char cmd[GS_CMD_SIZE]; - - if (! _gs_sock[cid].connect) return -1; - - _gs_sock[cid].connect = false; -// delete _gs_sock[cid].data; -// _gs_sock[cid].data = NULL; - sprintf(cmd, "AT+NCLOSE=%X", cid); - return command(cmd, GSRES_NORMAL); -} - -int GSwifi::send (int cid, const char *buf, int len) { - int i; - Timer timeout; - - if (! _gs_sock[cid].connect) return -1; - - if ((_gs_sock[cid].protocol == GSPROT_TCP) || - (_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; -#ifdef GS_BULK - _gs.printf("\x1bZ%X%04d", cid, len); - for (i = 0; i < len; i ++) { - _gs_putc(buf[i]); -#ifdef DEBUG_VIEW - DBG("%c", buf[i]); -#endif - } -#else - _gs.printf("\x1bS%X", cid); - for (i = 0; i < len; i ++) { - if (buf[i] >= 0x20 && buf[i] < 0x7f) { - _gs_putc(buf[i]); -#ifdef DEBUG_VIEW - DBG("%c", buf[i]); -#endif - } - } - _gs_putc(0x1b); - _gs_putc('E'); -#endif - } else { - return -1; - } - timeout.start(); - while (!_gs_ok && !_gs_failure && timeout.read_ms() < GS_TIMEOUT); - return _gs_ok == 1 ? 0 : -1; -} - -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; -#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()); - _gs.printf("%04d", len); - for (i = 0; i < len; i ++) { - _gs_putc(buf[i]); -#ifdef DEBUG_VIEW - DBG("%c", buf[i]); -#endif - } -#else - _gs.printf("\x1bU%X", cid); - _gs.printf("%d.%d.%d.%d:%d:", host.getIp()[0], host.getIp()[1], host.getIp()[2], host.getIp()[3], host.getPort()); - for (i = 0; i < len; i ++) { - if (buf[i] >= 0x20 && buf[i] < 0x7f) { - _gs_putc(buf[i]); -#ifdef DEBUG_VIEW - DBG("%c", buf[i]); -#endif - } - } - _gs_putc(0x1b); - _gs_putc('E'); -#endif - } else { - return -1; - } - timeout.start(); - while (!_gs_ok && !_gs_failure && timeout.read_ms() < GS_TIMEOUT); - return _gs_ok == 1 ? 0 : -1; -} - -int GSwifi::recv (int cid, char *buf, int len) { - int r; - Timer timeout; - - if (_gs_sock[cid].data == NULL) return 0; - - timeout.start(); - while (_gs_sock[cid].data->use() == 0) { - if (timeout.read_ms() > GS_TIMEOUT) return 0; - } - timeout.stop(); - - r = _gs_sock[cid].data->get(buf, len); - return r; -} - -int GSwifi::recv (int cid, char *buf, int len, Host &host) { - int r; - Timer timeout; - - if (_gs_sock[cid].data == NULL) return 0; - - timeout.start(); - while (_gs_sock[cid].data->use() == 0) { - if (timeout.read_ms() > GS_TIMEOUT) return 0; - } - timeout.stop(); - - r = _gs_sock[cid].data->get(buf, len); - host = _from; - return r; -} - -bool GSwifi::isConnected (int cid) { - return _gs_sock[cid].connect; -} - -int GSwifi::httpGet (Host &host, const char *uri, const char *user, const char *pwd, int ssl, onGsReceiveFunc ponGsReceive) { - char cmd[GS_CMD_SIZE]; - - if (! _connect || _status != GSSTAT_READY) return -1; - - if (host.getIp().isNull()) { - if (getHostByName(host)) { - if (getHostByName(host)) return -1; - } - } - if (host.getPort() == 0) { - if (ssl) { - host.setPort(443); - } else { - host.setPort(80); - } - } - - command("AT+HTTPCONF=3,close", GSRES_NORMAL); // Connection: - sprintf(cmd, "AT+HTTPCONF=11,%s", host.getName()); // Host: - command(cmd, GSRES_NORMAL); - if (user && pwd) { - char tmp[GS_CMD_SIZE], tmp2[GS_CMD_SIZE]; - snprintf(tmp, sizeof(tmp), "%s:%s", user, pwd); - base64encode(tmp, strlen(tmp), tmp2, sizeof(tmp2)); - sprintf(cmd, "AT+HTTPCONF=2,Basic %s", tmp2); // Authorization: - command(cmd, GSRES_NORMAL); - } else { - command("AT+HTTPCONFDEL=2", GSRES_NORMAL); - } - command("AT+HTTPCONFDEL=5", GSRES_NORMAL); - command("AT+HTTPCONFDEL=7", GSRES_NORMAL); - - sprintf(cmd, "AT+HTTPOPEN=%d.%d.%d.%d,%d", host.getIp()[0], host.getIp()[1], host.getIp()[2], host.getIp()[3], host.getPort()); - if (ssl) { - strcat(cmd, ",1"); - } - if (command(cmd, GSRES_HTTP)) return -1; - newSock(_cid, GSTYPE_CLIENT, GSPROT_HTTPGET, ponGsReceive); - - sprintf(cmd, "AT+HTTPSEND=%d,1,%d,%s", _cid, GS_TIMEOUT / 1000, uri); // GET - command(cmd, GSRES_NORMAL); - - return _cid; -} - -int GSwifi::httpGet (Host &host, const char *uri, int ssl, onGsReceiveFunc ponGsReceive) { - return httpGet (host, uri, NULL, NULL, ssl, ponGsReceive); -} - -int GSwifi::httpPost (Host &host, const char *uri, const char *body, const char *user, const char *pwd, int ssl, onGsReceiveFunc ponGsReceive) { - char cmd[GS_CMD_SIZE]; - int i, len; - - if (! _connect || _status != GSSTAT_READY) return -1; - - if (host.getIp().isNull()) { - if (getHostByName(host)) { - if (getHostByName(host)) return -1; - } - } - if (host.getPort() == 0) { - if (ssl) { - host.setPort(443); - } else { - host.setPort(80); - } - } - len = strlen(body); - - command("AT+HTTPCONF=3,close", GSRES_NORMAL); // Connection: - sprintf(cmd, "AT+HTTPCONF=11,%s", host.getName()); // Host: - command(cmd, GSRES_NORMAL); - sprintf(cmd, "AT+HTTPCONF=5,%d", len); // Content-Length: - command(cmd, GSRES_NORMAL); - command("AT+HTTPCONF=7,application/x-www-form-urlencoded", GSRES_NORMAL); // Content-type: - if (user && pwd) { - char tmp[GS_CMD_SIZE], tmp2[GS_CMD_SIZE]; - snprintf(tmp, sizeof(tmp), "%s:%s", user, pwd); - base64encode(tmp, strlen(tmp), tmp2, sizeof(tmp2)); - sprintf(cmd, "AT+HTTPCONF=2,Basic %s", tmp2); // Authorization: - command(cmd, GSRES_NORMAL); - } else { - command("AT+HTTPCONFDEL=2", GSRES_NORMAL); - } - - sprintf(cmd, "AT+HTTPOPEN=%d.%d.%d.%d,%d", host.getIp()[0], host.getIp()[1], host.getIp()[2], host.getIp()[3], host.getPort()); - if (ssl) { - strcat(cmd, ",1"); - } - if (command(cmd, GSRES_HTTP)) return -1; - newSock(_cid, GSTYPE_CLIENT, GSPROT_HTTPPOST, ponGsReceive); - - sprintf(cmd, "AT+HTTPSEND=%d,3,%d,%s,%d", _cid, GS_TIMEOUT / 1000, uri, len); // POST - command(cmd, GSRES_NORMAL); - - _gs.printf("\x1bH%X", _cid); - for (i = 0; i < len; i ++) { - _gs_putc(body[i]); - DBG("%c", body[i]); - } - - return _cid; -} - -int GSwifi::httpPost (Host &host, const char *uri, const char *body, int ssl, onGsReceiveFunc ponGsReceive) { - return httpPost (host, uri, body, NULL, NULL, ssl, ponGsReceive); -} - int GSwifi::certAdd (const char *name, const char *cert, int len) { int i; char cmd[GS_CMD_SIZE]; @@ -1344,36 +1078,21 @@ for (int i = 0; i < 10; i ++) { wait_ms(10); poll_cmd(); - _buf_cmd.clear(); + _buf_cmd.flush(); } return 0; } -int GSwifi::base64encode (char *input, int length, char *output, int len) { - // code from - // Copyright (c) 2010 Donatien Garnier (donatiengar [at] gmail [dot] com) - static const char base64[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; - unsigned int c, c1, c2, c3; +int GSwifi::setRegion (int reg) { + char cmd[GS_CMD_SIZE]; - if (len < ((((length-1)/3)+1)<<2)) return -1; - for(unsigned int i = 0, j = 0; i<length; i+=3,j+=4) { - c1 = ((((unsigned char)*((unsigned char *)&input[i])))); - c2 = (length>i+1)?((((unsigned char)*((unsigned char *)&input[i+1])))):0; - c3 = (length>i+2)?((((unsigned char)*((unsigned char *)&input[i+2])))):0; + if (_status != GSSTAT_READY) return -1; - c = ((c1 & 0xFC) >> 2); - output[j+0] = base64[c]; - c = ((c1 & 0x03) << 4) | ((c2 & 0xF0) >> 4); - output[j+1] = base64[c]; - c = ((c2 & 0x0F) << 2) | ((c3 & 0xC0) >> 6); - output[j+2] = (length>i+1)?base64[c]:'='; - c = (c3 & 0x3F); - output[j+3] = (length>i+2)?base64[c]:'='; - } - output[(((length-1)/3)+1)<<2] = '\0'; - return 0; + sprintf(cmd, "AT+WREGDOMAIN=%d", reg); + return command(cmd, GSRES_NORMAL); } + int GSwifi::from_hex (int ch) { return isdigit(ch) ? ch - '0' : tolower(ch) - 'a' + 10; } @@ -1383,50 +1102,6 @@ return hex[code & 15]; } -int GSwifi::urlencode (char *str, char *buf, int len) { - // code from - // Copyright (c) 2010 Donatien Garnier (donatiengar [at] gmail [dot] com) -// char *pstr = str, *buf = (char*)malloc(strlen(str) * 3 + 1), *pbuf = buf; - char *pstr = str, *pbuf = buf; - - if (len < (strlen(str) * 3 + 1)) return -1; - while (*pstr) { - if (isalnum(*pstr) || *pstr == '-' || *pstr == '_' || *pstr == '.' || *pstr == '~') - *pbuf++ = *pstr; - else if (*pstr == ' ') - *pbuf++ = '+'; - else - *pbuf++ = '%', *pbuf++ = to_hex(*pstr >> 4), *pbuf++ = to_hex(*pstr & 15); - pstr++; - } - *pbuf = '\0'; - return 0; -} - -int GSwifi::urldecode (char *str, char *buf, int len) { - // code from - // Copyright (c) 2010 Donatien Garnier (donatiengar [at] gmail [dot] com) -// char *pstr = str, *buf = (char*)malloc(strlen(str) + 1), *pbuf = buf; - char *pstr = str, *pbuf = buf; - - if (len < (strlen(str) / 3 - 1)) return -1; - while (*pstr) { - if (*pstr == '%') { - if (pstr[1] && pstr[2]) { - *pbuf++ = from_hex(pstr[1]) << 4 | from_hex(pstr[2]); - pstr += 2; - } - } else if (*pstr == '+') { - *pbuf++ = ' '; - } else { - *pbuf++ = *pstr; - } - pstr++; - } - *pbuf = '\0'; - return 0; -} - int GSwifi::x2i (char c) { if (c >= '0' && c <= '9') { return c - '0'; @@ -1450,6 +1125,7 @@ return 0; } + #ifdef DEBUG // for test void GSwifi::dump () { @@ -1476,13 +1152,13 @@ int GSwifi::getc() { char c; - if (_buf_cmd.use()) { - _buf_cmd.get(&c); + if (! _buf_cmd.isEmpty()) { + _buf_cmd.dequeue(&c); } /* } else if (_gs_sock[0].data != NULL) { - _gs_sock[0].data->get(&c); + _gs_sock[0].data->dequeue(&c); } */ return c; @@ -1493,7 +1169,7 @@ } int GSwifi::readable() { - return _buf_cmd.use(); + return ! _buf_cmd.isEmpty(); // return _buf_cmd.use() || (_gs_sock[0].data != NULL && _gs_sock[0].data->use()); } #endif