void add_client( RTSP_buffer ** rtsp_list, tsocket fd, RTSP_proto proto) { RTSP_buffer *p = NULL, *pp = NULL; // Add a client if (*rtsp_list == NULL) { *rtsp_list = xnew0(RTSP_buffer); p = *rtsp_list; } else { for (p = *rtsp_list; p != NULL; p = p->next) { pp = p; } if (pp != NULL) { if (!(pp->next = (RTSP_buffer *) calloc(1, sizeof(RTSP_buffer)))) { FATALLOGG("Could not alloc memory"); return; } p = pp->next; p->next = NULL; } } RTSP_initserver(p, fd, proto); INFOLOGG("Incoming RTSP connection accepted on socket %d", p->fd); }
void AddClient(RTSP_buffer **ppRtspList, int fd) { RTSP_buffer *pRtsp=NULL,*pRtspNew=NULL; #ifdef RTSP_DEBUG fprintf(stderr, "%s, %d\n", __FUNCTION__, __LINE__); #endif //在链表头部插入第一个元素 if (*ppRtspList==NULL) { /*分配空间*/ if ( !(*ppRtspList=(RTSP_buffer*)calloc(1,sizeof(RTSP_buffer)) ) ) { fprintf(stderr,"alloc memory error %s,%i\n", __FILE__, __LINE__); return; } pRtsp = *ppRtspList; } else { //向链表中插入新的元素 for (pRtsp=*ppRtspList; pRtsp!=NULL; pRtsp=pRtsp->next) { pRtspNew=pRtsp; } /*在链表尾部插入*/ if (pRtspNew!=NULL) { if ( !(pRtspNew->next=(RTSP_buffer *)calloc(1,sizeof(RTSP_buffer)) ) ) { fprintf(stderr, "error calloc %s,%i\n", __FILE__, __LINE__); return; } pRtsp=pRtspNew->next; pRtsp->next=NULL; } } //设置最大轮询id号 if(g_s32Maxfd < fd) { g_s32Maxfd = fd; } /*初始化新添加的客户端*/ RTSP_initserver(pRtsp,fd); fprintf(stderr,"Incoming RTSP connection accepted on socket: %d\n",pRtsp->fd); }