000
09.04.2005, 23:02 Uhr
~Fox
Gast
|
Hi! Also ich habe das hier:
C++: |
#include <stdlib.h> #include <stdio.h> #include <string.h> #include <unistd.h> #include <sys/types.h> #include <sys/socket.h> #include <netinet/in.h> #include <pthread.h>
#include "share/server.h" #include "share/string.h"
int main (void) { int server; int client; struct sockaddr_in server_address; struct sockaddr_in client_address; pthread_t *pthread; unsigned short int pthreadc;
server = socket (PF_INET, SOCK_STREAM, 0);
server_address.sin_family = AF_INET; server_address.sin_addr.s_addr = INADDR_ANY; server_address.sin_port = htons (36);
bind (server, (const struct sockaddr *) &server_address, sizeof (server_address));
listen (server, 5);
while (1) { client = accept (server, (struct sockaddr *) &client_address, (socklen_t *) sizeof (client_address)); if (pthread == NULL) { pthread = malloc (sizeof (pthread_t)); } else { pthreadc++; pthread = realloc (pthread, sizeof (pthread_t) * pthreadc + sizeof (pthread_t)); }
pthread_create ((pthread_t *) pthread [pthreadc], NULL, (void *) server_thread_go, &client); }
pthread_exit (NULL); close (server); }
int server_thread_go (void *client) { printf ("%d", client);
return 0; }
|
Bekomme aber einen von pthread_create verursachten Speicherzugriffsfehler, warum?
Thx Fox Dieser Post wurde am 09.04.2005 um 23:02 Uhr von Fox editiert. |