-
Notifications
You must be signed in to change notification settings - Fork 0
/
g_ubuf.c
executable file
·62 lines (52 loc) · 1.41 KB
/
g_ubuf.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/*-----------------------------------------*
g_ubuf.c
coded by H.B. Lee
Feb/2007
Revisioned Mya/2009
*-----------------------------------------*/
#include <stdio.h>
#include <stdlib.h>
#include "g_macros.h"
#include "g_config.h"
#include "g_ubuf.h"
/*******************************************/
/******** io buffer space management *******/
/*******************************************/
static UBUF Ubuf[MAX_UBUF_NUMBR];
void ubp_init()
{
int i;
for (i = 0; i < MAX_UBUF_NUMBR; i++) {
//Ubuf[i].buf = malloc(100);
Ubuf[i].buf = (BYTE *)malloc(MAX_NODE_PSIZE*2 +1);
Ubuf[i].bsz = MAX_NODE_PSIZE*2;
ubp_free(&Ubuf[i]);
}
}
void ubp_free(UBUF *ubp)
{
ubp->sp = ubp->cp = ubp->buf;
ubp->mp = ubp->sp + ubp->bsz/2;
ubp->ep = ubp->sp + ubp->bsz; /* for unlimited big cdma packet */
ubp->rn = ubp->phase = ubp->flag = 0;
}
UBUF *ubp_alloc(int ufd)
{
int i;
for (i = 0; i < MAX_UBUF_NUMBR; i++) {
if (!Ubuf[i].flag) {
ubp_flush(&Ubuf[i]);
Ubuf[i].flag = UBUF_USE;
Ubuf[i].ufd = ufd;
return(&Ubuf[i]);
}
}
return(NULL);
}
void ubp_flush(UBUF *ubp)
{
ubp->sp = ubp->cp = ubp->buf;
ubp->mp = ubp->sp + ubp->bsz/2;
ubp->ep = ubp->sp + ubp->bsz; /* for unlimited big cdma packet */
ubp->rn = ubp->phase = ubp->sp[0] = 0;
}