Files
wget2/examples/quic_write_read.c
harshmohan07 86b1a41492 * The test case written for QUIC is working with some issues. [skip ci]
* While building the file, the server that is created as the child process is not getting exited.
* But the server is terminated while the test is run individually.
2024-02-06 01:59:17 +05:30

57 lines
1.5 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_quic_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, data);
if (ret < 0) {
break;
}
}
return ret;
}