Linux移植记录

本文章用以记录自己在windows到linux移植过程中遇到的各种问题和各种坑。

linux头文件,作用有待继续学习= =

#ifndef	ZRLINUX_H
#define ZRLINUX_H

// linux头文件
#include <assert.h>
#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
#include <pthread.h>
#include <netdb.h>
#include <unistd.h>
#include <errno.h>
#include <semaphore.h>
#include <stdarg.h>
#include <ifaddrs.h>

#include <sys/times.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/timeb.h>
#include <sys/ioctl.h>
#include <sys/sem.h>
#include <sys/stat.h>

#include <netinet/in.h>
#include <netinet/tcp.h>
#include <net/if.h>

#include <arpa/inet.h>

// 自定义
#define EvoUDPOperatorLibAPI  //extern "C"

// windows变量
#define PVOID void*
#define BOOL int
#define FALSE 0
#define TRUE 1
#define Sleep(time) usleep(time * 1000);

// socket差异
#define FAR  
#define SOCKET int
#define socklen_t int
#define ssize_t int
#define SOCKET_ERROR -1
#define INVALID_SOCKET -1
#define closesocket close
#define ioctlsocket fcntl

// linux临界区
#define CRITICAL_SECTION pthread_mutex_t
#define InitializeCriticalSection(mutex) pthread_mutex_init(mutex,0)
#define DeleteCriticalSection(mutex) pthread_mutex_destroy(mutex)
#define EnterCriticalSection(mutex) pthread_mutex_lock(mutex)
#define LeaveCriticalSection(mutex) pthread_mutex_unlock(mutex)

// linux信号量

// linux线程

// linux错误号
extern int errno;

#endif

系统调用差异


socket网络差异

select函数

linux下的select函数需要设置第一位参数为set的大小;


ioctlsocket和fcntl

windows下:

u_long mode = 0;
ioctlsocket(s, FIONBIO, &mode);
控制为阻塞方式

u_long mode = 1;
ioctlsocket(s, FIONBIO, &mode);
控制为非阻塞方式 


linux下:

int flags = fcntl(socket, F_GETFL, 0); 
fcntl(socket, F_SETFL, flags | O_NONBLOCK);

将非阻塞的设置回阻塞可以用

int flags = fcntl(socket, F_GETFL, 0); 
fcntl(socket, F_SETFL, flags & ~O_NONBLOCK);


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值