|
sock.h 源码
#ifndef _SOCK_H
#define _SOCK_H
/* system includes */
#include <openssl/ssl.h> //需包含openssl库
#include <openssl/md5.h>
/* Engine socket pool element structure */ //sock 池 元素的结构体
typedef struct {
int fd;
SSL *ssl;
BIO *bio;
MD5_CTX context;
int status;
int lock;
char *buffer;
char *extracted;
int size;
int total_size;
} SOCK;
/* global vars exported */ //全局变量
extern SOCK *sock;
/* Prototypes */
extern void free_sock(SOCK *);
extern void init_sock(void);
#endif
sock.c源码
#include <string.h>
#include "memory.h"
#include "utils.h"
#include "list.h"
#include "sock.h"
#include "layer4.h"
#include "ssl.h"
#include "main.h"
/* global var */ //全局变量 SOCK指针
SOCK *sock = NULL;
/* Close the descriptor */ //关闭sock 如果有ssl句柄则关闭销毁
static void
close_sock(SOCK * sock_obj)
{
if (sock_obj->ssl) {
SSL_shutdown(sock_obj->ssl);
SSL_free(sock_obj->ssl);
}
close(sock_obj->fd);
}
/* Destroy the socket handler */ //销毁socket句柄
void
free_sock(SOCK * sock_obj)
{
DBG("Freeing fd:%d\n", sock_obj->fd);
close_sock(sock_obj);
FREE(sock_obj);
}
/* Init socket handler */ //sock句柄的初始化
void
init_sock(void)
{
sock = (SOCK *) MALLOC(sizeof (SOCK));
memset(sock, 0, sizeof (SOCK));
thread_add_event(master, tcp_connect_thread, sock, 0);
}
调用位置:
main.c 中
/* Register the GET request */
init_sock();
Scheduler.c中
/* Add simple event thread. */
thread_t *
thread_add_event(thread_master_t * m, int (*func) (thread_t *)
, void *arg, int val)
{
thread_t *thread;
assert(m != NULL);
thread = thread_new(m);
thread->type = THREAD_EVENT;
thread->id = 0;
thread->master = m;
thread->func = func;
thread->arg = arg;
thread->u.val = val;
thread_list_add(&m->event, thread);
return thread;
}
其中 /* global vars */
thread_master_t *master = NULL;
版权声明:本文为博主原创文章,未经博主允许不得转载。 |
|
|