From bbcafa43c08c84b502f318c1f7a17dbc1de32df3 Mon Sep 17 00:00:00 2001 From: stamrakar Date: Wed, 6 Nov 2024 00:37:01 -0700 Subject: [PATCH] sockettest still failing --- aesd-char-driver/main.c | 10 +++--- server/aesdsocket.c | 77 ++++++++++++++++++++++------------------- 2 files changed, 47 insertions(+), 40 deletions(-) diff --git a/aesd-char-driver/main.c b/aesd-char-driver/main.c index c6a47c1..19ea715 100644 --- a/aesd-char-driver/main.c +++ b/aesd-char-driver/main.c @@ -186,18 +186,18 @@ static long aesd_adjust_file_offset(struct file *filp, unsigned int write_cmd, u goto errout; } - if(write_cmd_offset > dev->circular.entry[write_cmd].size-1) + if(write_cmd_offset >= dev->circular.entry[write_cmd].size) { retval = -EINVAL; PDEBUG("write_cmd_offset was out of range. %zu", retval); goto errout; } - i = dev->circular.out_offs; - while (i != write_cmd) + i = 0; + while (i < write_cmd) { filp->f_pos += dev->circular.entry[i].size; - i = (i+1) % AESDCHAR_MAX_WRITE_OPERATIONS_SUPPORTED; + i++; } filp->f_pos += write_cmd_offset; @@ -215,7 +215,7 @@ long aesd_unlocked_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) if (_IOC_TYPE(cmd) != AESD_IOC_MAGIC) return -ENOTTY; if (_IOC_NR(cmd) > AESDCHAR_IOC_MAXNR) return -ENOTTY; - + ssize_t retval; if (filp == NULL) { diff --git a/server/aesdsocket.c b/server/aesdsocket.c index 9bd9688..aabe93a 100644 --- a/server/aesdsocket.c +++ b/server/aesdsocket.c @@ -357,7 +357,7 @@ void *threadfunc(void *args) int errnum; do{ bytes_rx = recv(thread_func_args->thread_info.afd, my_buffer+supplementBuf, BUF_SIZE-1, 0); - //syslog(LOG_DEBUG, "Receiving: %s", my_buffer); + syslog(LOG_DEBUG, "Receiving: %s", my_buffer); // syslog(LOG_DEBUG, "new_fd is %d", thread_func_args->thread_info.afd); syslog(LOG_DEBUG, "I have received %ld bytes", bytes_rx); if (bytes_rx < 0) @@ -379,6 +379,7 @@ void *threadfunc(void *args) syslog(LOG_ERR, "sscanf() fail"); syslog(LOG_ERR, "sscanf() call err. error string is %s", strerror(errno)); } + syslog(LOG_DEBUG, "seekto.write_cmd is %u and seekto.write_cmd_offset is %u", seekto.write_cmd, seekto.write_cmd_offset); int result_ret = ioctl(recvfile_fd, AESDCHAR_IOCSEEKTO, &seekto); if (result_ret == 0) { @@ -440,7 +441,7 @@ void *threadfunc(void *args) nr = write(recvfile_fd, my_buffer, supplementBuf); - total_size += supplementBuf; + //total_size += supplementBuf; rc = pthread_mutex_unlock(&writeSocket); if (rc != 0) @@ -460,51 +461,55 @@ void *threadfunc(void *args) } syslog(LOG_DEBUG, "Write completed to recvfile_fd"); + // #if(USE_AESD_CHAR_DEVICE == 1) + // if(close(recvfile_fd) == -1) + // { + // syslog(LOG_ERR, "Failed to close recvfile."); + // syslog(LOG_ERR, "error string is %s", strerror(errno)); + // } + // else + // { + // syslog(LOG_DEBUG, "HANDLE CLOSED 1"); + // } + // #endif + + skip_write: + #if (USE_AESD_CHAR_DEVICE == 1) + if(close(recvfile_fd) == -1) + { + syslog(LOG_ERR, "Failed to close recvfile."); + syslog(LOG_ERR, "error string is %s", strerror(errno)); + } + else + { + syslog(LOG_DEBUG, "HANDLE CLOSED 1"); + } + #endif - #if(USE_AESD_CHAR_DEVICE == 1) - if(close(recvfile_fd) == -1) - { - syslog(LOG_ERR, "Failed to close recvfile."); - syslog(LOG_ERR, "error string is %s", strerror(errno)); - } - else - { - syslog(LOG_DEBUG, "HANDLE CLOSED 1"); - } - #endif - } -skip_write: + } free(my_buffer); my_buffer = NULL; + + #if (USE_AESD_CHAR_DEVICE == 0) - - #if (USE_AESD_CHAR_DEVICE==0) - if(lseek(recvfile_fd, 0, SEEK_SET) == -1) + #else + recvfile_fd = open(recvfile, O_RDWR | O_CREAT | O_APPEND, 0644); + if (recvfile_fd == -1) { - syslog(LOG_ERR, "server: lseek"); - perror("server: lseek set"); + int err = errno; + syslog(LOG_ERR, "%s failed to open. errno -> %d", recvfile, err); + syslog(LOG_ERR, "Error: %s", strerror(errno)); closeAll(EXIT_FAILURE); } - #else - recvfile_fd = open(recvfile, O_RDWR | O_CREAT | O_APPEND, 0644); - if (recvfile_fd == -1) - { - /*error*/ - int err = errno; - syslog(LOG_ERR, "%s failed to open. errno izz -> %d", recvfile, err); - syslog(LOG_ERR, "Error: %s", strerror(errno)); - closeAll(EXIT_FAILURE); - } - else - { - syslog(LOG_DEBUG, "HANDLE OPENED 2"); - } + else + { + syslog(LOG_DEBUG, "HANDLE OPENED 2"); + } #endif - rc = pthread_mutex_lock(&writeSocket); if (rc != 0) @@ -526,7 +531,9 @@ void *threadfunc(void *args) //printf("total size here is %ld, \n", total_size); + total_size = lseek(recvfile_fd, 0, SEEK_END); syslog(LOG_DEBUG, "total size here is %ld", total_size); + lseek(recvfile_fd, 0, SEEK_SET); while ((bytes_read = read(recvfile_fd, send_my_buffer, total_size)) > 0) { syslog(LOG_DEBUG, "bytes_read is %ld", bytes_read); //syslog(LOG_DEBUG, "Sending: %s",send_my_buffer);