#ifndef PATH_MAX
# define PATH_MAX 255
-#endif
+#endif
#define nghttp3_arraylen(A) (sizeof(A) / sizeof(*(A)))
#define CLIENTBIDIOPEN 0x04 /* bidirectional open by the client (something like 0, 4, 8 ...) */
#define SERVERUNIOPEN 0x08 /* unidirectional open by the server (3, 7 and 11) */
#define SERVERCLOSED 0x10 /* closed by the server (us) */
-#define TOBEREMOVED 0x20 /* marked for removing in read_from_ssl_ids, removed after processing all events */
+#define TOBEREMOVED 0x20 /* marked for removing in read_from_ssl_ids, */
+ /* it will be removed after processing all events */
#define ISLISTENER 0x40 /* the stream is a listener from SSL_new_listener() */
#define ISCONNECTION 0x80 /* the stream is a connection from SSL_accept_connection() */
memset(h3ssl, 0, sizeof(struct h3ssl));
ssl_ids = h3ssl->ssl_ids;
- for (i = 0; i < MAXSSL_IDS; i++) {
+ for (i = 0; i < MAXSSL_IDS; i++)
ssl_ids[i].id = UINT64_MAX;
- }
h3ssl->id_bidi = UINT64_MAX;
/* restore the fileprefix */
}
return NULL;
}
-static void replace_ids_connection(struct h3ssl *h3ssl, SSL *oldstream, SSL *newstream )
+static void replace_ids_connection(struct h3ssl *h3ssl, SSL *oldstream, SSL *newstream)
{
struct ssl_id *ssl_ids;
int i;
}
}
-
/* remove the ids marked for removal */
static void remove_marked_ids(struct h3ssl *h3ssl)
{
return -1;
}
+/* check that all streams opened by the client are closed */
static int are_all_clientid_closed(struct h3ssl *h3ssl)
{
struct ssl_id *ssl_ids;
continue;
printf("are_all_clientid_closed: %llu status %d : %d\n",
(unsigned long long) ssl_ids[i].id, ssl_ids[i].status, CLIENTUNIOPEN | CLIENTCLOSED);
- if (ssl_ids[i].status & (CLIENTUNIOPEN | CLIENTCLOSED)) {
- printf("are_all_clientid_closed: %llu closed\n", (unsigned long long) ssl_ids[i].id);
- SSL_free(ssl_ids[i].s);
- ssl_ids[i].s = NULL;
- ssl_ids[i].id = UINT64_MAX;
- continue;
- }
if (ssl_ids[i].status & CLIENTUNIOPEN) {
+ if (ssl_ids[i].status & CLIENTCLOSED) {
+ printf("are_all_clientid_closed: %llu closed\n",
+ (unsigned long long) ssl_ids[i].id);
+ SSL_free(ssl_ids[i].s);
+ ssl_ids[i].s = NULL;
+ ssl_ids[i].id = UINT64_MAX;
+ continue;
+ }
printf("are_all_clientid_closed: %llu open\n", (unsigned long long) ssl_ids[i].id);
return 0;
}
vname = nghttp3_rcbuf_get_buf(name);
vvalue = nghttp3_rcbuf_get_buf(value);
- fwrite(vname.base, vname.len, 1, stderr);
- fprintf(stderr, ": ");
- fwrite(vvalue.base, vvalue.len, 1, stderr);
- fprintf(stderr, "\n");
+ fwrite(vname.base, vname.len, 1, stdout);
+ fprintf(stdout, ": ");
+ fwrite(vvalue.base, vvalue.len, 1, stdout);
+ fprintf(stdout, "\n");
if (token == NGHTTP3_QPACK_TOKEN__PATH) {
int len = (((vvalue.len) < (MAXURL)) ? (vvalue.len) : (MAXURL));
if (vvalue.base[1] == '\0') {
strncpy(h3ssl->url, "index.html", MAXURL);
} else {
- memcpy(h3ssl->url, &vvalue.base[1], len - 1);
+ memcpy(h3ssl->url, vvalue.base + 1, len - 1);
+ h3ssl->url[len - 1] = '\0';
}
} else {
memcpy(h3ssl->url, vvalue.base, len);
rstream = SSL_new_stream(conn, SSL_STREAM_FLAG_UNI);
if (rstream != NULL) {
printf("=> Opened on %llu\n",
- (unsigned long long)SSL_get_stream_id(rstream));
+ (unsigned long long)SSL_get_stream_id(rstream));
} else {
fprintf(stderr, "=> Stream == NULL!\n");
goto err;
pstream = SSL_new_stream(conn, SSL_STREAM_FLAG_UNI);
if (pstream != NULL) {
printf("=> Opened on %llu\n",
- (unsigned long long)SSL_get_stream_id(pstream));
+ (unsigned long long)SSL_get_stream_id(pstream));
} else {
fprintf(stderr, "=> Stream == NULL!\n");
goto err;
id = SSL_get_stream_id(item->desc.value.ssl);
printf("revent READ on %llu\n", (unsigned long long)id);
r = quic_server_read(h3conn, s, id, h3ssl);
- if (r == 0)
+ if (r == 0) {
+ uint8_t msg[1];
+ size_t l = sizeof(msg);
+
+ /* check that the other side is closed */
+ r = SSL_read(s, msg, l);
+ printf("SSL_read tells %d\n", r);
+ if (r > 0) {
+ ret = -1;
+ goto err;
+ }
+ r = SSL_get_error(s, r);
+ if (r != SSL_ERROR_ZERO_RETURN) {
+ ret = -1;
+ goto err;
+ }
+ set_id_status(id, TOBEREMOVED, h3ssl);
+ has_ids_to_remove++;
continue;
+ }
if (r == -1) {
ret = -1;
goto err;
ssl_ids = h3ssl->ssl_ids;
for (i = 0; i < MAXSSL_IDS; i++) {
- if (ssl_ids[i].s != NULL && (ssl_ids[i].status & ISCONNECTION || ssl_ids[i].status & ISLISTENER)) {
+ if (ssl_ids[i].s != NULL &&
+ (ssl_ids[i].status & ISCONNECTION || ssl_ids[i].status & ISLISTENER)) {
if (SSL_handle_events(ssl_ids[i].s))
ERR_print_errors_fp(stderr);
}
if (stat(filename, &st) == 0) {
/* Only process regular files */
if (S_ISREG(st.st_mode)) {
- printf("get_file_length %s %lld\n", filename, (unsigned long long) st.st_size);
+ printf("get_file_length %s %lld\n", filename, (unsigned long long) st.st_size);
return st.st_size;
}
}
int ok = 0;
int hassomething = 0;
SSL *listener = NULL;
- struct h3ssl h3ssl;
nghttp3_conn *h3conn = NULL;
+ struct h3ssl h3ssl;
SSL *ssl;
-
- h3ssl.fileprefix = getenv("FILEPREFIX");
+ char *fileprefix = getenv("FILEPREFIX");
/* Create a new QUIC listener. */
if ((listener = SSL_new_listener(ctx, 0)) == NULL)
int hasnothing;
init_ids(&h3ssl);
+ h3ssl.fileprefix = fileprefix;
printf("listener: %p\n", (void *)listener);
add_ids_listener(listener, &h3ssl);
if (!hasnothing) {
SSL *newssl = get_ids_connection(&h3ssl);
+
printf("hasnothing nothing WAIT %d!!!\n", h3ssl.close_done);
if (newssl == NULL)
newssl = listener;