当前位置: 技术问答>linux和unix
高分请人帮忙,对网络编程熟悉的高手请进
来源: 互联网 发布时间:2016-05-30
本文导语: 以下为3个VC下编写的头文件,请人帮忙改为Linux下可用的头文件,最好把需要的头文件也加上;这个东西我改了好长时间了,还是经验不足,越改问题越多,干脆把源代码拿上来了。 留下邮箱 谢谢 | ...
以下为3个VC下编写的头文件,请人帮忙改为Linux下可用的头文件,最好把需要的头文件也加上;这个东西我改了好长时间了,还是经验不足,越改问题越多,干脆把源代码拿上来了。
留下邮箱 谢谢
留下邮箱 谢谢
|
还是有点问题 下面这段 改成linux中的程序 C和C++都可以
class CSemaphoreEx
{
public:
CSemaphoreEx(){m_Semaphore = NULL; }
CSemaphoreEx(LONG initCount,LONG maxCount) {m_Semaphore = NULL; Create(initCount,maxCount); }
~CSemaphoreEx() {
try {
CloseHandle(m_Semaphore);
}
catch(...) {}
m_Semaphore = NULL;
}
HANDLE Create(LONG initCount,LONG maxCount) {
_ASSERT(NULL==m_Semaphore);
return( m_Semaphore = CreateSemaphore(NULL,initCount,maxCount,NULL));
}
BOOL Release(LONG lReleaseCount,LPLONG lpPreviousCount){
_ASSERT(NULL!=m_Semaphore);
return( ::ReleaseSemaphore(m_Semaphore,lReleaseCount,lpPreviousCount));
}
DWORD WaitFor(DWORD dwMilliseconds = INFINITE){
_ASSERT(NULL!=m_Semaphore);
return( ::WaitForSingleObject(m_Semaphore,dwMilliseconds ));
}
DWORD WaitForEx(DWORD dwMilliseconds,BOOL bAlertable) {
_ASSERT(NULL!=m_Semaphore);
return( ::WaitForSingleObjectEx(m_Semaphore,dwMilliseconds,bAlertable));
}
protected:
private:
HANDLE m_Semaphore; // 信号量
};
如上代码:
HANDLE --->sem_t;
LONG -->long
DWORD-->u_int32_t
_ASSERT-->assert
WaitForSingleObject-->join
CreateSemaphore-->sem_init
ReleaseSemaphore-->sem_wati
class CSemaphoreEx
{
public:
CSemaphoreEx(){m_Semaphore = NULL; }
CSemaphoreEx(LONG initCount,LONG maxCount) {m_Semaphore = NULL; Create(initCount,maxCount); }
~CSemaphoreEx() {
try {
CloseHandle(m_Semaphore);
}
catch(...) {}
m_Semaphore = NULL;
}
HANDLE Create(LONG initCount,LONG maxCount) {
_ASSERT(NULL==m_Semaphore);
return( m_Semaphore = CreateSemaphore(NULL,initCount,maxCount,NULL));
}
BOOL Release(LONG lReleaseCount,LPLONG lpPreviousCount){
_ASSERT(NULL!=m_Semaphore);
return( ::ReleaseSemaphore(m_Semaphore,lReleaseCount,lpPreviousCount));
}
DWORD WaitFor(DWORD dwMilliseconds = INFINITE){
_ASSERT(NULL!=m_Semaphore);
return( ::WaitForSingleObject(m_Semaphore,dwMilliseconds ));
}
DWORD WaitForEx(DWORD dwMilliseconds,BOOL bAlertable) {
_ASSERT(NULL!=m_Semaphore);
return( ::WaitForSingleObjectEx(m_Semaphore,dwMilliseconds,bAlertable));
}
protected:
private:
HANDLE m_Semaphore; // 信号量
};
如上代码:
HANDLE --->sem_t;
LONG -->long
DWORD-->u_int32_t
_ASSERT-->assert
WaitForSingleObject-->join
CreateSemaphore-->sem_init
ReleaseSemaphore-->sem_wati
|
linux 编程我个人觉的有几本书不错.
1.tcp/IP详解第一卷,作为网络编程的理论基础;
2.unix环境高级编程
3.unix系统编程
4.unix网络编程
1.tcp/IP详解第一卷,作为网络编程的理论基础;
2.unix环境高级编程
3.unix系统编程
4.unix网络编程