| 476 | } |
| 477 | |
| 478 | static bool _openSocket |
| 479 | ( |
| 480 | SOCKET *ps, |
| 481 | const char *host, |
| 482 | unsigned port |
| 483 | ) |
| 484 | { |
| 485 | #ifdef MINIHTTP_USE_POLARSSL |
| 486 | int s; |
| 487 | int err = net_connect(&s, host, port); |
| 488 | if(err) |
| 489 | { |
| 490 | traceprint("open_ssl: net_connect(%s, %u) returned %d\n", host, port, err); |
| 491 | return false; |
| 492 | } |
| 493 | #else |
| 494 | sockaddr_in addr; |
| 495 | if(!_Resolve(host, port, &addr)) |
| 496 | { |
| 497 | traceprint("RESOLV ERROR: %s\n", _GetErrorStr(_GetError()).c_str()); |
| 498 | return false; |
| 499 | } |
| 500 | |
| 501 | SOCKET s = socket(AF_INET, SOCK_STREAM, 0); |
| 502 | |
| 503 | if(!SOCKETVALID(s)) |
| 504 | { |
| 505 | traceprint("SOCKET ERROR: %s\n", _GetErrorStr(_GetError()).c_str()); |
| 506 | return false; |
| 507 | } |
| 508 | |
| 509 | if (::connect(s, (sockaddr*)&addr, sizeof(sockaddr))) |
| 510 | { |
| 511 | traceprint("CONNECT ERROR: %s\n", _GetErrorStr(_GetError()).c_str()); |
| 512 | return false; |
| 513 | } |
| 514 | #endif |
| 515 | |
| 516 | *ps = s; |
| 517 | return true; |
| 518 | } |
| 519 | |
| 520 | #ifdef MINIHTTP_USE_POLARSSL |
| 521 | void traceprint_ssl |
no test coverage detected