Ò׽ؽØÍ¼Èí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö160KB

linux socketѧϰ±Ê¼Ç£¨µÚ¶þÕ£©


ÓòºÍµØÖ·×å
    ÓÐÒ»¸öºÜÇ¡µ±µÄ±ÈÓ÷˵Ã÷Ì×½Ó¿Ú±à³Ì£¬Ì׽ӿھͺñȵ绰£¬¶øµç»°ÍøÖеĵ绰ºÅÂë¾ÍºÃÏñÌ×½Ó¿ÚµØÖ·¡£ËµÃ÷Ì×½Ó¿Ú¿ÉÒÔÓÃÌØ¶¨µÄµØÖ·À´±êʾ×Ô¼º¡£²¢²»ÊÇËùÓеÄÌ×½Ó¿Ú¶¼ÐèÒªµØÖ·£¬±ÈÈçÎÞÃûÌ׽ӿھͲ»ÐèÒªµØÖ·£¬ÀýÈ纯Êýsocketpair(2)¾ÍÉú³ÉÁËÒ»¶Ô»¥Ïà¿ÉÒÔÁ¬½Óµ«ÊÇȴûÓеØÖ·µÄÌ×½Ó¿Ú¡£ÊéÖбÈÓ÷˵¾ÍºÃÏñÊÇÀäսʱÆÚËÕÁªºÍÃÀ¹úÖ®¼äµÄÈÈÏߵ绰һÑù£¬Ö±½ÓÏàÁ¬£¬²»ÐèÒªµç»°ºÅÂë¡£
    Óò(domain)£¬ÔÚsocketÖУ¬²»½ö¿ÉÒÔÖ§³ÖTCP/IPЭÒ飬Ҳ¿ÉÒÔÖ§³ÖÆäËûЭÒ飬socketÖеIJÎÊýdomainµÄ×÷ÓÃÕýÔÚÓÚ´Ë¡£»Ø¹ËÒ»ÏÂsocketpair(2)º¯ÊýµÄÓï·¨¿ÉÒÔ¿´µ½¡£
    #include <sys/types.h>
    #include <sysy/socket.h>
   
    int socketpair( int domain , int type , int protocol , int sv[2] );
    ÔÚsocketpair(2)º¯ÊýÖУ¬domain²ÎÊýҪôÊÇAF_LOCAL,ҪôÊÇAF_UNIX. ÆäʵËûÃÇÊǵȼ۵ġ£AF_LOCALµÄǰ׺AF±íʾµØÖ·×壨address family£©£¬domain²ÎÊýµÄÓÃ;¾ÍÊÇ˵Ã÷º¯ÊýÊDzÉÓÃÄĸöµØÖ·×å¡£Ö®ºó»¹»á³öÏÖPF_µÄºê£¬ÏÖÔÚ¿ÉÒÔÔÝʱÈÏΪÊǵȼ۵ġ£
    AF_LOCAL±íʾʹÓñ¾µØµØÖ·¹æÔòÀ´Éú³ÉµØÖ·£¬AF_INET±íʾʹÓÃIPµØÖ·¹æÔòÀ´Éú³ÉµØÖ·¡£BSDµÄ½â¾ö·½°¸ÌṩÁËÒ»ÖÖͨÓõĵØÖ·½á¹¹ÈçÏ£º
    #include <sys/socket.h>
   
    struct sockaddr{
        sa_family_t sa_family ;         /* µØÖ·×å */
        char  sa_data[14] ;               /* µØÖ·Êý¾Ý */
    };
    ¶ÔÓÚ±à³ÌÕßÀ´Ëµ£¬Í¨ÓÃÌ×½Ó¿Ú±¾ÉíûÓÐʲôÓô¦£¬µ«ÊÇËüΪÆäËûµØÖ·½á¹¹ÌṩÁËÒ»¸öÖØÒªµÄ²Î¿¼Ä£ÐÍ£¬±ÈÈçËùÓеĵØÖ·¶¼ÒªÔڽṹÖеÄͬÑùλÖö¨Òåsa_family³ÉÔ±£¬ÒòΪËû¾ö¶¨ÁËÔõô·­Òë½á¹¹Öаüº¬µØÖ·ÐÅÏ¢µÄ×Ö½Ú¡£
    Éú³É±¾µØµØÖ·AF_LOCAL»òÕßAF_UNIXµÄµØÖ·µÄ½á¹¹ÃûÊÇsockaddr_un.
    ÔÚLinuxÖУ¬Ê¹ÓÃ×îÆÕ±éµÄµØÖ·×åÊÇAF_INET.¾ßÓÐIPv4Ì×½Ó¿ÚµØÖ·µÄÌ×½Ó¿Ú¿ÉÒÔÓëTCP/IPÉÏµÄÆäËûÖ÷»ú½øÐÐͨÐÅ¡£Ò»ÏÂÊÇCÓïÑÔÃèÊöµÄ½á¹¹sockadd


Ïà¹ØÎĵµ£º

LINUX C Á´±í·â×°


main.c
//³õʼ»¯¶ÓÁÐ
void InitQueue(LiQueue *q)
{
  q=(LiQueue*)malloc(sizeof(LiQueue));
    q->front=q->rear=NULL;
}
//ÅжÏÊÇ·ñΪ¿Õ
int QueueEmpty(LiQueue *q)
{
 if(q->rear==NULL)
 {
  return 1;
 }
 else
 {
  ......

LINUX϶àÏ̺߳ÍÐźÅ

˵ʵ»°£¬ÐźÅÊÇÎÒÌÖÑáµÄ¶«Î÷£¬ÔÚÎÒЩµÄ´úÂëÖУ¬ÎÒ¶¼ÏëÓÃ×î¼òµ¥µÄ°ì·¨À´´¦ÀíËü£¬ÏÖÔÚÓöµ½¶àÏß³ÌÖÐÐźŵĴ¦Àí£¬APUEÖеÄ˵·¨Ò²¿´µÃ²»ÊǺܶ®£¬CSDNÖÐһλÅóÓÑÓÐÈçϵÄ×ܽᣬÏȼÇÔÚÕâÀï¡£
1. ĬÈÏÇé¿öÏ£¬ÐźŽ«ÓÉÖ÷½ø³Ì½ÓÊÕ´¦Àí£¬¾ÍËãÐźŴ¦Àíº¯ÊýÊÇÓÉ×ÓÏß³Ì×¢²áµÄ
2. ÿ¸öÏ߳̾ùÓÐ×Ô¼ºµÄÐÅºÅÆÁ±Î×Ö£¬¿ÉÒÔʹÓÃsigprocmaskº¯ ......

װLinuxϵͳ

½ñÌì×°ÁËÒ»ÌìµÄLinuxϵͳ£¬ÓëÆä˵°²×°»¹²»Èç˵ÊÇÏÂÔØÁËÒ»Ì죬ÏȺó×°ÁËfedora core 4£¬fedora core 6£¬×îºó×°fedora core 8ÖÕÓÚ¿ÉÒÔÓÃÁË£¬Ã¿¸ö¶¼ÊÇ3G¶à£¬ÒòΪÔÚѧУµÄ¹¤×÷ÊÒ£¬ËùÒÔÏÂÔØËÙ¶ÈÆ½¾ù¿ÉÒÔ´ïµ½1.9M²»µ½£¬Õâ¿ÉÊÇÏÞËٵ쬾ÍËãÕâÑùÎҵĵçÄÔÒ²ÒòΪÏÂÔØËÙ¶ÈÌ«¿ìËÀÁËN»ØÁË£¬¶¼ÊÇÇ¿ÖÆPowerµÄ£¬ÕæµÃ×°µÃÓеãÓôÃÆ°¡£¬×°FC4ÊÇÒ ......

linuxÁ½¸ö³ÌÐòͨ¹ý¹²ÏíÄÚ´æÍ¨ÐŵÄÒ»¸ö¼òµ¥Àý×Ó

д¹²ÏíÄÚ´æ³ÌÐò£º
/*
* File: server.cpp
* Author: centos
*˵Ã÷£º´Ó¼üÅ̶ÁÈëÊý¾Ý£¬´æ·ÅÔÚ¹²ÏíÄÚ´æÖС£
* Created on 2010Äê3ÔÂ1ÈÕ, ÏÂÎç3:44
*/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <sys/types.h>
#include < ......

linux ÏÔʽµ÷Óà ×Ô¼ºÐ´µÄ¶¯Ì¬¿â

~/test
|
|
|------main.c
|------lib
|        |
|        |------StringLen.h
|        |------Strlen.c
|        |------Strnlen.c
----------------StringLen.h:
#ifndef _STRING ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØÍ¼ | ¸ÓICP±¸09004571ºÅ