Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1347846
  • 博文数量: 370
  • 博客积分: 10654
  • 博客等级: 中将
  • 技术积分: 4396
  • 用 户 组: 普通用户
  • 注册时间: 2010-08-07 15:44
文章分类

全部博文(370)

文章存档

2012年(36)

2011年(195)

2010年(139)

分类: LINUX

2012-01-19 15:57:06

出错处理模块的设计和实现

该模块由bterror.hbterror.c文件构成,主要定义了一些错误类型,以及发生导致程序终止的致命性错误时程序的响应。

bterror.h

#ifndef BTERROR_H

#define BTERROR_H

#define FILE_FD_ERR -1   // 无效的文件描述符

#define FILE_READ_ERR -2   // 读文件失败

#define FILE_WRITE_ERR -3   // 写文件失败

#define INVALID_METAFILE_ERR -4   // 无效的种子文件

#define INVALID_SOCKET_ERR -5   // 无效的套接字

#define INVALID_TRACKER_URL_ERR -6   // 无效的Tracker URL

#define INVALID_TRACKER_REPLY_ERR -7   // 无效的Tracker回应

#define INVALID_HASH_ERR -8   // 无效的hash

#define INVALID_MESSAGE_ERR -9   // 无效的消息

#define INVALID_PARAMETER_ERR -10  // 无效的函数参数

#define FAILED_ALLOCATE_MEM_ERR -11  // 申请动态内存失败

#define NO_BUFFER_ERR -12 // 没有足够的缓冲区

#define READ_SOCKET_ERR -13  // 读套接字失败

#define WRITE_SOCKET_ERR -14  // 写套接字失败

#define RECEIVE_EXIT_SIGNAL_ERR -15  // 接收到退出程序的信号

// 用于提示致命性的错误,程序将终止

void btexit(int errno,char *file,int line);

#endif

以下是bterror.c文件:

bterror.c

#include 

#include 

#include 

#include "bterror.h"

void btexit(i nt errno,char *file,int line)

{

     printf("exit at %s : %d with error number : %d\n",file, line, errno);

     exit(errno);

}

阅读(2216) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~