Created
August 21, 2012 20:36
-
-
Save vndmtrx/3419219 to your computer and use it in GitHub Desktop.
Função ev_clientedadosdisp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| static void ev_clientedadosdisp(int sock) { | |
| int concluido = 0; | |
| ssize_t qtd; | |
| char buf[TAMBUFFER]; | |
| while (1) { | |
| qtd = read(sock, buf, sizeof(buf)); | |
| if (qtd == -1) { | |
| // Se o erro for EAGAIN significa que todos os dados foram lidos. | |
| if (errno != EAGAIN) { | |
| perror ("read"); | |
| concluido = 1; | |
| } | |
| break; | |
| } else if (qtd == 0) { | |
| // Fim do arquivo. Socket foi fechado pelo cliente remoto. | |
| concluido = 1; | |
| break; | |
| } | |
| // Enviando de volta para o cliente remoto (unsafe). | |
| qtd = write(sock, buf, qtd); | |
| if (qtd == -1) { | |
| perror("write"); | |
| } | |
| } | |
| if (concluido) { | |
| printf("Conexao cliente terminada no descritor %d.\n", sock); | |
| close(sock); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment