�������: ������ (���� | �����������) ��RU opennet.me  
The OpenNET Project / Index page

[ ������� /+++ | ����� | ���� | ]

������� ������������ / ������ "������������ ��� Linux" / ���������� ���������
next up previous contents index
Next: ������� Up: ������ � �������� Previous: ������� shutdown   Contents   Index

������� close

��� ������� ��������� ����� � ��������� ��� ���������� � ���� �������. � ������� �� ������� shutdown ������� close.����� ���������� ��������� ���� �������� � �������, ����������� "����������", � �� ��������� �������� ����������.

��������:

int close (int s);

�������� ������� - ����������� �����-����������.

������-�������� ��������� "������"

#include <sys/types.h>
#include <sys/socket.h>
#include <sys/un.h>
#include <stdio.h>
#define ADDRESS "mysocket" /* ����� ��� ����� */
void main ()
{	char c;
	int i, s, len;
	FILE *fp;
	struct sockaddr_un sa;
/* �������� ���� �����-����������: */
	if ((s = socket (AF_UNIX, SOCK_STREAM, 0))<0)
	{
	perror ("client: socket"); exit(1);
	}
/* ������� �����, �� �������� ����� ����������� � ��������: */
	sa.sun_family = AF_UNIX;
	strcpy (sa.sun_path, ADDRESS);
/* �������� ��������� � ��������: */
	len = sizeof ( sa.sun_family) + strlen ( sa.sun_path);
	if ( connect ( s, &sa, len) < 0 ){
		perror ("client: connect"); exit (1);
	}


/*--------------------------------------------- */

/* ������ ��������� ������� */
	fp = fdopen (s, "r");
	c = fgetc (fp);
/* ������������ ���������� �� �������
 ...................................
*/

/* �������� ����� ������� */
	send (s, "client", 7, 0);

/* ���������� ������ � ��������, ���� � ���� ����
 �������������
 ............................
*/

/* ��������� ����� ������   */
	close (s);
	exit (0);
}

������-�������� ��������� "������"

#include <sys/types.h>
#include <sys/socket.h>
#include <sys/un.h>
#include <stdio.h>
#define ADDRESS "mysocket" /* ����� ��� ����� */
void main ()
{ 	char c;
	int i, d, d1, len, ca_len;
	FILE *fp;
	struct sockaddr_un sa, ca;
/* �������� ���� �����-����������: */
	if((d = socket (AF_UNIX, SOCK_STREAM, 0)) < 0)
	{
	 perror ("client: socket"); exit (1);
	}
/* ������� �����, c ������� ����� ����������� ������� */
	sa.sun_family = AF_UNIX;
	strcpy (sa.sun_path, ADDRESS);
/*  ��������� ����� � �������;
	���������� ���� � ������ ADDRESS, ���� �� ����������,
	��� ����, ����� ����� bind ���������� �������
*/
	unlink (ADDRESS);
	len = sizeof ( sa.sun_family) + strlen (sa.sun_path);
	if ( bind ( d, &sa, len) < 0 ) {
		perror ("server: bind"); exit (1);
	}
/* ������� ������� �� ����� */
	if ( listen ( d, 5) < 0 ) {
		perror ("server: listen"); exit (1);
	}
/* ����������� � �������� ����� ������������� ����� � 	������������ d1:
*/
	if (( d1 = accept ( d, &ca, &ca_len)) < 0 ) {
		perror ("server: accept"); exit (1);
	}

/* ------------------------------------------ */

/* ����� �������: */
	send (d1, "server", 7, 0);

/* ������ ������ ������� */
	fp = fdopen (d1, "r");
	c = fgetc (fp);
/* ................................ */
/* ������������ ������ �������,
 �������� ����� � �.�.
   ...........................
*/

/* ��������� ����� ������ */
	close (d1);
	exit (0);
}



Alex Otwagin 2002-12-16



������:
PostgresPro
Inferno Solutions
Hosting by Hoster.ru
�������:

�������� �� �����
���������� �� ���������
Created 1996-2026 by Maxim Chirkov
��������, ����������, ����������