Skip to content

Instantly share code, notes, and snippets.

@vndmtrx
Created August 21, 2012 20:36
Show Gist options
  • Select an option

  • Save vndmtrx/3419219 to your computer and use it in GitHub Desktop.

Select an option

Save vndmtrx/3419219 to your computer and use it in GitHub Desktop.
Função ev_clientedadosdisp
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