[LTP] [PATCH v3] aio_cancel_7-1: Write into a socket

Cyril Hrubis chrubis@suse.cz
Thu Aug 28 12:26:15 CEST 2025


Hi!
> -	unlink(tmpfname);
> +	/* Socket buffer size is twice the maximum message size */
> +	bufsize /= 2;
>  
>  	/* create AIO req */
>  	for (i = 0; i < BUF_NB; i++) {
>  		aiocb[i] = calloc(1, sizeof(struct aiocb));
>  
>  		if (aiocb[i] == NULL) {
> -			printf(TNAME " Error at malloc(): %s\n",
> +			printf(TNAME " Error at calloc(): %s\n",
>  			       strerror(errno));
> -			close(fd);
> +			cleanup();
>  			return PTS_UNRESOLVED;
>  		}
> 
> -		aiocb[i]->aio_fildes = fd;
> -		aiocb[i]->aio_buf = malloc(BUF_SIZE);
> +		aiocb[i]->aio_fildes = fds[0];
> +		aiocb[i]->aio_buf = malloc(bufsize);
>  
>  		if (aiocb[i]->aio_buf == NULL) {
>  			printf(TNAME " Error at malloc(): %s\n",
>  			       strerror(errno));
> -			close(fd);
> +			cleanup();
>  			return PTS_UNRESOLVED;
>  		}
>  
> -		aiocb[i]->aio_nbytes = BUF_SIZE;
> +		aiocb[i]->aio_nbytes = bufsize;
>  		aiocb[i]->aio_offset = 0;
>  		aiocb[i]->aio_sigevent.sigev_notify = SIGEV_NONE;
>  
>  		if (aio_write(aiocb[i]) == -1) {
>  			printf(TNAME " loop %d: Error at aio_write(): %s\n",
>  			       i, strerror(errno));
> -			close(fd);
> +			cleanup();
>  			return PTS_FAIL;
>  		}
>  	}

Do I get it right that we queue eight aio writes and four of them finish
before the socket buffer is full and then the writing gets stuck with
the fift one?

So in the end we have four finished writes, one in progress and three
canceled?

-- 
Cyril Hrubis
chrubis@suse.cz


More information about the ltp mailing list