📄 csocketsender.cpp
字号:
//
// CSocketSender.cpp
//
/*-----------------------------------------------------*\
HQ Tech, Make Technology Easy!
More information, please go to http://hqtech.nease.net.
/*-----------------------------------------------------*/
#include "stdafx.h"
#include "CSocketSender.h"
#include "defines.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
//////////////////////////////////////////////////////////////////////////////
CSocketSender::CSocketSender()
{
mFile = NULL;
mPaused = FALSE;
}
CSocketSender::~CSocketSender()
{
if (mFile)
{
fclose(mFile);
mFile = NULL;
}
}
void CSocketSender::SetSource(CMediaInfo & inMedia)
{
mSource = inMedia;
// Open the source file
if (mFile)
{
fclose(mFile);
mFile = NULL;
}
mFile = fopen(mSource.mFilePath, "rb");
ASSERT(mFile);
}
void CSocketSender::SetPaused(BOOL inPaused)
{
mPaused = inPaused;
}
void CSocketSender::SendingLoop(void)
{
// Send the extra checking bytes first
if (mSource.mCheckOffset2 > 0)
{
long len = mSource.mFileSize - mSource.mCheckOffset2;
char * pExtra = new char[len];
fseek(mFile, mSource.mCheckOffset2, SEEK_SET);
int bytes = fread(pExtra, sizeof(char), len, mFile);
// Re-point to the file beginning
fseek(mFile, 0, SEEK_SET);
bytes = send(mSocket, pExtra, len, 0);
delete[] pExtra;
}
// Send the normal media content
char buf[PACK_SIZE];
int readLen = 0;
int sentLen = 0;
while (mIsSending)
{
if (mPaused)
{
Sleep(10);
continue;
}
readLen = fread(buf, sizeof(char), PACK_SIZE, mFile);
if (readLen > 0)
{
sentLen = send(mSocket, buf, readLen, 0);
if (sentLen == SOCKET_ERROR)
{
Detach(); // Close the socket
mIsSending = FALSE;
break;
}
// Maybe reach the end of the file
if (readLen < PACK_SIZE)
{
mIsSending = FALSE;
break;
}
}
else
{
mIsSending = FALSE;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -