Skip to content

Commit

Permalink
sockettest still failing
Browse files Browse the repository at this point in the history
  • Loading branch information
stamrakar authored and stamrakar committed Nov 6, 2024
1 parent 302932b commit bbcafa4
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 40 deletions.
10 changes: 5 additions & 5 deletions aesd-char-driver/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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)
{
Expand Down
77 changes: 42 additions & 35 deletions server/aesdsocket.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
{
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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);
Expand Down

0 comments on commit bbcafa4

Please sign in to comment.