🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: es.comp.os.linux.programacion
Article #16851

Re: Problemillas con los sockets

#16851
From: batsman batsman
Date: Mon, 20 Mar 2000 00:00
84 lines
3984 bytes
-----BEGIN PGP SIGNED MESSAGE-----

In article <38D20C42.93C42E02@mtgsystem.com>, Paco Orts wrote:
>
>Bueno, este es el c�digo de la funci�n que utilizo para leer todo lo que me manden
>hasta que alcanze un salto de linea. netSystem.h es una cabecera con la
>declaraci�n de la funci�n leerLinea.

Bueno, este c�digo no est� probado, pero deber�a rular, apenas le he hecho 4
cambios
>
>#include <netSystem.h>
>#include <string.h>
>#include <stdio.h>
>#include <stdlib.h>
>#include <unistd.h>
>
>///////////////////////////////////////////////////////
>//  Funci�n encargada de leer un m�ximo de longBuf
>//  caracteres del socket sfd y guardarlos en buf.
>//  Termina tambi�n cuando se encuentre un salto de
>//  l�nea.
>//  Devuelve el n�mero de caracteres leidos.
>///////////////////////////////////////////////////////
>int leerLinea (int sfd, char *buf, int longBuf)
>{
   char buffer[2];
>  int bytesRestantes = longBuf;
>  int bytesRecibidos;
>
   buf[0] = '\0';
   buffer[1] = '\0'; /* para delimitar la cadena */
>  while (bytesRestantes > 0)
>  {
     /*buffer[0] = ' '; no vale para nada, read machaca el buffer */
>    bytesRecibidos = read (sfd, buffer, 1);
>    if (bytesRecibidos == -1)
>    {
>      printf ("ERROR. Al recibir desde el servidor");
>      return -1;
>    }
>    bytesRestantes -= bytesRecibidos;
>    strcat(buf, buffer); //bytesRecibidos;
>    if (buffer[0] == '\n') break;
>  }
  return (longBuf - bytesRestantes); /* �por qu� no return strlen(buf) ? */
>}
>
>Y por si tambi�n es lo que quieres, donde llamo a esta funci�n es:
>
>       recepcion = leerLinea (hdlNetUse, cadena, 100);
>        if (recepcion == -1)
>          printf ("Error en la recepci�n desde el servidor");
>        if (!strcmp (cadena, "COMMUNICATION ACCEPTED\n"))
>        {
>
>aqu� si hago un telnet nunca me pasa del if.


- -- 
              _           _                             
             | |__   __ _| |_ ___ _ __ ___   __ _ _ __  
             | '_ \ / _` | __/ __| '_ ` _ \ / _` | '_ \ 
             | |_) | (_| | |_\__ \ | | | | | (_| | | | |
             |_.__/ \__,_|\__|___/_| |_| |_|\__,_|_| |_|
  ________________________________________________________________
 |Visit   |  http://www.geocities.com/SiliconValley/Vista/2075    |
 |Linux   |  http://www.geocities.com/SiliconValley/Vista/4289    |
  ----------------------------------------------------------------
  Real email: batsman dot geo at yahoo dot com

-----BEGIN PGP SIGNATURE-----
Version: 2.6.3ia
Charset: noconv
Comment: Public key via email: send mail with Subject: [PGPKEY]

iQEVAwUBONZ2hr0Y27yr0iefAQEbAAf+JExEHedXaO6+Timjyh9khBeXpXgiYpoI
Lg4EcR2evLayRKhg0V5MWTZ6GUVCIu00eR2UCMn7AL38rJ7dO+2tvyCAcgdjlOpi
OcZgwN1yJSvmgGabgs0QfjtOqfN0nVPboxhPP04j86EAYkJiQII6H9SIjSY8+jMV
SCdiVe4KocRANfeg9096uS/Z+fMHsFI9P2Fw0nmgDXhcVQGwfJdmGrxpq2bcvLsA
/YCXPsoZ7RHgZ11TEBEdElT8BEX6GHa6zmiPjfDEhJZkvutYKr82Pe4xouvBxKlC
IC0HtafBgTqEQzcDI3JCZrdemVLlYfD7OAzDxu7CuSMBLEdV0O7sIw==
=bnwT
-----END PGP SIGNATURE-----
Technical Details
Message-ID: <bqs5b8.1h.ln@simpsons4ever>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail
References: <38CFDF82.BD9CA6A3@mtgsystem.com> <38D0A222.8EA901FF@NOSPAM.inicia.es> <38D111BE.7DA15CCE@mtgsystem.com> <8asrra$i5d$3@simancas.uva.es> <38D20C42.93C42E02@mtgsystem.com>

Show Full Headers
Complete Article Headers
X-Google-Language: SPANISH,ASCII
X-Google-Thread: f86c8,58a23ab56d6ca5b2
X-Google-Attributes: gidf86c8,public
From: batsman@simpsons4ever. (batsman)
Subject: Re: Problemillas con los sockets
Date: 2000/03/20
Message-ID: <bqs5b8.1h.ln@simpsons4ever>
X-Deja-AN: 600079800
Content-Transfer-Encoding: 8bit
References: <38CFDF82.BD9CA6A3@mtgsystem.com> <38D0A222.8EA901FF@NOSPAM.inicia.es> <38D111BE.7DA15CCE@mtgsystem.com> <8asrra$i5d$3@simancas.uva.es> <38D20C42.93C42E02@mtgsystem.com>
Content-Type: text/plain; charset=iso-8859-1
X-Complaints-To: abuse@news.wanadoo.es
X-Trace: m2newsread.uni2.es 953584191 62.36.16.43 (Mon, 20 Mar 2000 21:29:51 MET)
Organization: Wanadoo Usenet News - Visita http://www.wanadoo.es/
Mime-Version: 1.0
Reply-To: see_signature-mira_firma
NNTP-Posting-Date: Mon, 20 Mar 2000 21:29:51 MET
Newsgroups: es.comp.os.linux.programacion