mirror of
https://gitlab.com/gnuwget/wget2.git
synced 2026-02-01 14:41:08 +00:00
57 lines
1.3 KiB
C
57 lines
1.3 KiB
C
/**
|
|
* Demostrate write and read using QUIC stack with a QUIC echo
|
|
* server set up at local host.
|
|
*/
|
|
|
|
#include <wget.h>
|
|
#include <string.h>
|
|
|
|
int main(void) {
|
|
int ret;
|
|
const uint16_t port = 5556;
|
|
const char *hostname = "localhost";
|
|
|
|
wget_logger_set_stream(wget_get_logger(WGET_LOGGER_DEBUG), stderr);
|
|
wget_logger_set_stream(wget_get_logger(WGET_LOGGER_ERROR), stderr);
|
|
wget_logger_set_stream(wget_get_logger(WGET_LOGGER_INFO), stdout);
|
|
|
|
wget_quic *quic = wget_quic_init();
|
|
if (!quic) {
|
|
fprintf(stderr, "Error in wget_quic_init()\n");
|
|
return -1;
|
|
}
|
|
|
|
const char *key_path = "/home/hmk/wget2/examples/credentials/ca.pem";
|
|
wget_ssl_set_config_string(WGET_SSL_CA_FILE, key_path);
|
|
wget_quic_set_ssl_hostname(quic, hostname);
|
|
|
|
|
|
ret = wget_quic_connect(quic, hostname, port);
|
|
if (ret < 0) {
|
|
fprintf(stderr, "Error in wget_quic_connect()\n");
|
|
wget_quic_deinit(&quic);
|
|
return 1;
|
|
}
|
|
|
|
wget_quic_stream *stream = wget_quic_stream_init_bidirectional(quic);
|
|
if (!stream) {
|
|
fprintf(stderr, "ERROR: wget_quic_stream_init_bidirectional\n");
|
|
return 1;
|
|
}
|
|
|
|
const char *data = "Hello World!";
|
|
ret = wget_quic_stream_push(stream, data, strlen(data), REQUEST_BYTE);
|
|
if (ret <= 0) {
|
|
fprintf(stderr, "ERROR: wget_quic_stream_push\n");
|
|
return 1;
|
|
}
|
|
|
|
while (1) {
|
|
ret = wget_quic_rw_once(quic, stream);
|
|
if (ret < 0)
|
|
break;
|
|
}
|
|
|
|
return ret;
|
|
}
|