Annotation of ansh/src/proc.c, revision 1.1
1.1 ! misho 1: /*************************************************************************
! 2: * (C) 2011 AITNET - Sofia/Bulgaria - <office@aitnet.org>
! 3: * by Michael Pounov <misho@elwix.org>
! 4: *
! 5: * $Author: misho $
! 6: * $Id: global.h,v 1.2 2011/06/08 12:45:40 misho Exp $
! 7: *
! 8: *************************************************************************/
! 9: #include "global.h"
! 10: #include "anshd.h"
! 11: #include "proc.h"
! 12:
! 13:
! 14: struct tagProc *
! 15: InitProc(int h, struct sockaddr *sa, u_short id, int len)
! 16: {
! 17: struct tagProc *proc;
! 18:
! 19: FTRACE(5);
! 20:
! 21: proc = malloc(sizeof(struct tagProc));
! 22: if (!proc) {
! 23: ERR("Not enough memory #%d - %s", errno, strerror(errno));
! 24: return NULL;
! 25: } else
! 26: memset(proc, 0, sizeof(struct tagProc));
! 27: proc->proc_sock = h;
! 28: proc->proc_id = id;
! 29: if (sa)
! 30: memcpy(&proc->proc_cli, sa, sizeof(struct sockaddr));
! 31:
! 32: proc->proc_blen = len;
! 33: proc->proc_buf_[0] = malloc(proc->proc_blen);
! 34: if (!proc->proc_buf_[0]) {
! 35: free(proc);
! 36: proc = NULL;
! 37: }
! 38: proc->proc_buf_[1] = malloc(proc->proc_blen);
! 39: if (!proc->proc_buf_[1]) {
! 40: free(proc->proc_buf_[0]);
! 41: free(proc);
! 42: proc = NULL;
! 43: }
! 44:
! 45: SLIST_INSERT_HEAD(&pH, proc, proc_next);
! 46: return proc;
! 47: }
! 48:
! 49: void
! 50: FiniProcByID(u_short id)
! 51: {
! 52: struct tagProc *proc;
! 53:
! 54: SLIST_FOREACH(proc, &pH, proc_next)
! 55: if (proc->proc_id == id) {
! 56: SLIST_REMOVE(&pH, proc, tagProc, proc_next);
! 57: FreeProc(&proc);
! 58: }
! 59: }
! 60:
! 61: void
! 62: FreeProc(struct tagProc ** __restrict proc)
! 63: {
! 64: FTRACE(5);
! 65:
! 66: assert(proc && *proc);
! 67: if (!*proc)
! 68: return;
! 69:
! 70: if ((*proc)->proc_buf_[1])
! 71: free((*proc)->proc_buf_[1]);
! 72: if ((*proc)->proc_buf_[0])
! 73: free((*proc)->proc_buf_[0]);
! 74: free(*proc);
! 75: *proc = NULL;
! 76: }
! 77:
! 78: void
! 79: DestroyProc()
! 80: {
! 81: struct tagProc *proc;
! 82:
! 83: while ((proc = SLIST_FIRST(&pH))) {
! 84: SLIST_REMOVE_HEAD(&pH, proc_next);
! 85: FreeProc(&proc);
! 86: }
! 87: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>