ALT Linux Community general discussions
 help / color / mirror / Atom feed
From: "Alexandr R. Ogurtzoff" <iscander@mercuri.mk.ua>
To: community@altlinux.ru
Subject: Re: [Comm] Socet server bind debug
Date: Tue, 26 Aug 2003 11:56:56 +0300
Message-ID: <200308261156.56129.iscander@mercuri.mk.ua> (raw)
In-Reply-To: <200308261519.52960.den@academ.org>


> программка-то завершилась, а соединение еще не закрылось, см  netstat
Гхм! Действительно по netstat открыто, но как?
#include <stdio.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include "tst.h"

int ConnectionProccessing(int sd)
{
  char buffer[ BUFFER_SIZE ];
  int count;
  memset(buffer,0,sizeof(buffer));
  count= recv(sd, buffer,sizeof(buffer), 0);
    if (count < 0)
    {perror("Recive error, stop proccessing"); return 1;};
    if (count >= BUFFER_SIZE)
    {perror("Buffer overflow error"); return 2;};
    if (buffer[0]=='0')
    {perror("Conection terminated by remote side..."); return -1;};

   buffer[count+1]=0;
   printf("Recive \n %s \n", buffer);
   return 0;
}

int main (int argc, char *argv[] )
{
    int sd, exit_flag, port=DEFAULT_PORT;
    struct sockaddr_in  addr;

	printf ("\n %s test control started sucsesfully \n", argv[0]);
	 if((sd = socket(PF_INET,SOCK_STREAM,0))==-1)
	   panic("Error socket creation,exit");
 memset(&addr,0, sizeof(addr));
        addr.sin_family = PF_INET;
	addr.sin_port = htons(port);
	addr.sin_addr.s_addr = INADDR_ANY;
  if(  bind(sd, &addr, sizeof(addr) )!=0 )
	    panic("Error on binding, exit");
	 if ( listen(sd, MAX_LISTEN) !=0 )
	    panic("Error on listening,exit");
	exit_flag=0;
	while( exit_flag == 0 )
		{
		 int client, len=sizeof(addr);
			client = accept(sd, &addr,&len);
			printf ("\nHost ( %s : %d 
)",inet_ntoa(addr.sin_addr),ntohs(addr.sin_port));
			exit_flag=ConnectionProccessing(client);
			close(client);                                     /*Здесь закрыл*/
			printf ("\nClient closed\n");
		}
	close(sd);                                    /* И здесь тоже закрыл, факт?*/
	printf ("\n%s  finished\n", argv[0]);
	return 0;
}

 От вет на посылку '0' в качстве первого символа, то есть завершаем программку
[iscander@iscander gatedeamon]$ ./gatectrl

 ./test test control started sucsesfully

Conection terminated by remote side...: Success
Host ( 127.0.0.1 : 34431 )Client closed /*Здесь закрыл*/
 
./test test  finished /* И здесь тоже закрыл, факт?*/
[iscander@iscander gatedeamon]$ ./test

 ./test test control started sucsesfully
Error on binding, exit: Address already in use
Ну понятно что при этом он висит открытым
-- 
С наилучшими пожеланиями
Александр Огурцов



  parent reply	other threads:[~2003-08-26  8:56 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-08-26  7:52 Alexandr R. Ogurtzoff
2003-08-26  7:57 ` Maxim.Savrilov
2003-08-26  8:09 ` Someone Unknown
2003-08-26  8:23   ` Alexandr R. Ogurtzoff
2003-08-26  8:19     ` Denis S. Filimonov
2003-08-26  8:40       ` Someone Unknown
2003-08-26  8:56       ` Alexandr R. Ogurtzoff [this message]
2003-08-26  9:01         ` Denis S. Filimonov
2003-08-26  9:20           ` Alexandr R. Ogurtzoff
2003-08-26  9:25             ` Denis S. Filimonov
2003-08-26  9:37               ` Alexandr R. Ogurtzoff

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=200308261156.56129.iscander@mercuri.mk.ua \
    --to=iscander@mercuri.mk.ua \
    --cc=community@altlinux.ru \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

ALT Linux Community general discussions

This inbox may be cloned and mirrored by anyone:

	git clone --mirror http://lore.altlinux.org/community/0 community/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 community community/ http://lore.altlinux.org/community \
		mandrake-russian@linuxteam.iplabs.ru community@lists.altlinux.org community@lists.altlinux.ru community@lists.altlinux.com
	public-inbox-index community

Example config snippet for mirrors.
Newsgroup available over NNTP:
	nntp://lore.altlinux.org/org.altlinux.lists.community


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git