FreeBSD Bugzilla – Attachment 199096 Details for
Bug 231848
accept4() doesn't return a socket address when threading is involved
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
client code
cl.c (text/plain), 1.85 KB, created by
Anoop C S
on 2018-11-09 18:01:45 UTC
(
hide
)
Description:
client code
Filename:
MIME Type:
Creator:
Anoop C S
Created:
2018-11-09 18:01:45 UTC
Size:
1.85 KB
patch
obsolete
>#include <fcntl.h> >#include <stdio.h> >#include <stdlib.h> >#include <string.h> >#include <unistd.h> >#include <sys/un.h> >#include <pthread.h> >#include <sys/wait.h> >#include <sys/socket.h> > >#define NUM_THREADS 10 > >#define handle_error(msg) do { perror(msg); exit(EXIT_FAILURE); } while(0) > >static void *thread_worker(void *arg) >{ > int sfd, ret; > struct sockaddr_un addr; > char send_buf[64] = {0}; > char recv_buf[64] = {0}; > > sfd = socket(AF_UNIX, SOCK_STREAM, 0); > if (sfd == -1) > handle_error ("Failed to create socket"); > > memset(&addr, 0, sizeof(struct sockaddr_un)); > addr.sun_family = AF_UNIX; > strncpy(addr.sun_path, "/tmp/fd-pass.socket", sizeof(addr.sun_path) - 1); > > if (connect(sfd, (struct sockaddr *) &addr, sizeof(struct sockaddr_un)) == -1) > handle_error ("Failed to connect to socket"); > > snprintf (send_buf, sizeof(send_buf), "hello world"); > > ret = write (sfd, send_buf, sizeof(send_buf)); > if (ret == -1) > handle_error ("Failed to send data to server"); > > ret = read (sfd, recv_buf, sizeof(recv_buf)); > if (ret == -1) > handle_error ("Failed to read data from server"); > > fprintf (stdout, "%s\n", recv_buf); > > if (close(sfd) == -1) > handle_error ("Failed to close socket"); > > return NULL; >} > >int >main(int argc, char *argv[]) { > int i; > pthread_attr_t pthread_custom_attr; > > if (argc != 2) { > fprintf (stderr, "Usage: %s <thread-count>\n", argv[0]); > exit (1); > } > > pthread_t threads[atoi(argv[1])]; > > pthread_attr_init(&pthread_custom_attr); > > for (i = 0; i < atoi(argv[1]); i++) { > pthread_create(&threads[i], > &pthread_custom_attr, > thread_worker, > NULL); > } > > for (i = 0; i < atoi(argv[1]); i++) { > pthread_join(threads[i], NULL); > } > > pthread_attr_destroy(&pthread_custom_attr); > > exit(EXIT_SUCCESS); >}
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Raw
Actions:
View
Attachments on
bug 231848
:
199095
| 199096