Ciao a tutti,
avevo già iniziato un post su un errore, che ormai è risolto, ma voglio chiedervi se mi sapreste aiutare a far funzionare il pipe con per esempio 100 o 40 threads.
Quello che voglio fare è inviare al thread 67 dal thread 23 dei dati da far inviare via socket al 67.
Qui vengono generati threads:
Codice PHP:
while (1) {
unsigned int clientlen = sizeof(echoclient);
/* Wait for client connection */
if ((clientsock = accept(serversock, (struct sockaddr *) &echoclient, &clientlen)) < 0) {
Die("Failed to accept client connection");
}
fprintf(stdout, "Client connected: %s\n",
inet_ntoa(echoclient.sin_addr));
countrun++;
pid_t pid = fork();
if(!pid){
HandleClient(clientsock, piped);
fprintf(stdout, "Client Disconnected: %s\n", inet_ntoa(echoclient.sin_addr));
}
}
Qui sta l'azione che viene eseguita per ogni thread:
Codice PHP:
void HandleClient(int sock, int piped) {
char buffer[BUFFSIZE];
int received = -1;
if ((received = recv(sock, buffer, BUFFSIZE, 0)) < 0) {
Die("Failed to receive initial bytes from client");
}
while (received > 0) {
if (send(sock, buffer, received, 0) != received) {
Die("Failed to send bytes to client");
}
if ((received = recv(sock, buffer, BUFFSIZE, 0)) < 0) {
Die("Failed to receive additional bytes from client");
}
}
close(sock);
}