MCPcopy Create free account
hub / github.com/Heltec-Aaron-Lee/WiFi_Kit_series / connect

Method connect

libraries/HTTPClient/src/HTTPClient.cpp:1074–1125  ·  view source on GitHub ↗

* init TCP connection and handle ssl verify if needed * @return true if connection is ok */

Source from the content-addressed store, hash-verified

1072 * @return true if connection is ok
1073 */
1074bool HTTPClient::connect(void) {
1075 if (connected()) {
1076 if (_reuse) {
1077 log_d("already connected, reusing connection");
1078 } else {
1079 log_d("already connected, try reuse!");
1080 }
1081 while (_client->available() > 0) {
1082 _client->read();
1083 }
1084 return true;
1085 }
1086
1087#ifdef HTTPCLIENT_1_1_COMPATIBLE
1088 if (_transportTraits && !_client) {
1089 _tcpDeprecated = _transportTraits->create();
1090 if (!_tcpDeprecated) {
1091 log_e("failed to create client");
1092 return false;
1093 }
1094 _client = _tcpDeprecated.get();
1095 }
1096#endif
1097
1098 if (!_client) {
1099 log_d("HTTPClient::begin was not called or returned error");
1100 return false;
1101 }
1102#ifdef HTTPCLIENT_1_1_COMPATIBLE
1103 if (_tcpDeprecated && !_transportTraits->verify(*_client, _host.c_str())) {
1104 log_d("transport level verify failed");
1105 _client->stop();
1106 return false;
1107 }
1108#endif
1109 if (!_client->connect(_host.c_str(), _port, _connectTimeout)) {
1110 log_d("failed connect to %s:%u", _host.c_str(), _port);
1111 return false;
1112 }
1113
1114 // set Timeout for NetworkClient and for Stream::readBytesUntil() and Stream::readStringUntil()
1115 _client->setTimeout(_tcpTimeout);
1116
1117 log_d(" connected to %s:%u", _host.c_str(), _port);
1118
1119 /*
1120#ifdef ESP8266
1121 _client->setNoDelay(true);
1122#endif
1123 */
1124 return connected();
1125}
1126
1127/**
1128 * sends HTTP request header

Callers

nothing calls this directly

Calls 7

c_strMethod · 0.80
availableMethod · 0.45
readMethod · 0.45
createMethod · 0.45
verifyMethod · 0.45
stopMethod · 0.45
setTimeoutMethod · 0.45

Tested by

no test coverage detected