On 4/9/24 11:13 PM, Geliang Tang wrote:
+int send_recv_data(int lfd, int fd, uint32_t total_bytes)
+{
+       ssize_t nr_recv = 0, bytes = 0;
+       struct send_recv_arg arg = {
+               .fd     = lfd,
+               .bytes  = total_bytes,
+               .stop   = 0,
+       };
+       pthread_t srv_thread;
+       void *thread_ret;
+       char batch[1500];
+       int err;
+
+       err = pthread_create(&srv_thread, NULL, send_recv_server, (void *)&arg);
+       if (err) {
+               log_err("pthread_create");
+               return err;
+       }
+
+       /* recv total_bytes */
+       while (bytes < total_bytes && !READ_ONCE(arg.stop)) {
+               nr_recv = recv(fd, &batch,
+                              MIN(total_bytes - bytes, sizeof(batch)), 0);
+               if (nr_recv == -1 && errno == EINTR)
+                       continue;
+               if (nr_recv == -1)
+                       break;
+               bytes += nr_recv;
+       }
+
+       if (bytes != total_bytes) {
+               log_err("recv");
+               return -1;

This is still not right. It needs to write arg.stop and do pthread_join().

pw-bot: cr

+       }
+
+       WRITE_ONCE(arg.stop, 1);
+       pthread_join(srv_thread, &thread_ret);
+       if (IS_ERR(thread_ret)) {
+               log_err("thread_ret");
+               return -1;
+       }
+
+       return 0;
+}


Reply via email to