Click here to Skip to main content
16,012,316 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Simple question. Pin
Joaquín M López Muñoz25-Aug-03 10:39
Joaquín M López Muñoz25-Aug-03 10:39 
GeneralRe: Simple question. Pin
Jon Newman25-Aug-03 10:42
Jon Newman25-Aug-03 10:42 
GeneralTemplate for experts!! help Pin
berserker_r25-Aug-03 9:40
berserker_r25-Aug-03 9:40 
GeneralRe: Template for experts!! help Pin
Anonymous25-Aug-03 10:19
Anonymous25-Aug-03 10:19 
GeneralRe: Template for experts!! help Pin
Joaquín M López Muñoz25-Aug-03 10:27
Joaquín M López Muñoz25-Aug-03 10:27 
Questionhow to show data in internet explorer Pin
Binayak25-Aug-03 8:20
Binayak25-Aug-03 8:20 
AnswerRe: how to show data in internet explorer Pin
PremL26-Aug-03 5:39
PremL26-Aug-03 5:39 
Generalusing CArchive with CBlockingSocket class Pin
Mike Ellertson25-Aug-03 7:56
sussMike Ellertson25-Aug-03 7:56 
I just finished writing a class which should allow you to use a CArchive with a CBlockingSocket class. The same way CArchive works with CSocket, except this one is built on CBlockingSocket which doesn't implement 16-bit functions like CSocket.

Has anyone else tried this or have any knowledge on it? If so, are there any caviates with doing it this way? I've posed my code below for your paruzal:

The class name is CBlockingSocketFile and it emulates functionality in a CFile object. Basically so you can serialize to a CArchive and have it be transmitted across TCP/IP.

Here's the header file:
#define BLOCK_SOCK_TIMEOUT 15

class CBlockingSocketFile : public CFile  
{
	DECLARE_DYNAMIC(CBlockingSocketFile)
public:
//Constructors
	CBlockingSocketFile(CBlockingSocket *pNewSocket);
	virtual ~CBlockingSocketFile();

// Implementation
public:
	CBlockingSocket * pSocket;

	virtual UINT Read(void * pBuffer, UINT nBytes);
	virtual void Write(const void* pBuffer, UINT nBytes);
	virtual void Close();

private:
// Unsupported APIs
	virtual BOOL Open(LPCTSTR lpszFileName, UINT nOpenFlags, CFileException* pError = NULL);
	virtual CFile* Duplicate() const;
	virtual DWORD GetPosition() const;
	virtual LONG Seek(LONG lOff, UINT nFrom);
	virtual void SetLength(DWORD dwNewLen);
	virtual DWORD GetLength() const;
	virtual void LockRange(DWORD dwPos, DWORD dwCount);
	virtual void UnlockRange(DWORD dwPos, DWORD dwCount);
	virtual void Flush();
	virtual void Abort();
};


And here's the source file:

IMPLEMENT_DYNAMIC(CBlockingSocketFile, CFile);

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

CBlockingSocketFile::CBlockingSocketFile(CBlockingSocket *pNewSocket)
{
	if(pNewSocket == NULL) {
		DEBUG_LOG("CBlockingSocketFile constructor: NULL pointer assignment.");
		AfxThrowUserException();
	}
	pSocket = pNewSocket;
}

CBlockingSocketFile::~CBlockingSocketFile()
{

}

UINT CBlockingSocketFile::Read(void *pBuffer, UINT nBytes)
{
	return pSocket->Receive((char *)pBuffer, (const int)nBytes, BLOCK_SOCK_TIMEOUT);
}

void CBlockingSocketFile::Write(const void *pBuffer, UINT nBytes)
{
	pSocket->Write((const char*)pBuffer, (const int)nBytes, BLOCK_SOCK_TIMEOUT);
}

void CBlockingSocketFile::Close()
{
	pSocket->Close();
}

// Unsupported APIs
BOOL Open(LPCTSTR lpszFileName, UINT nOpenFlags, CFileException* pError = NULL)
{ 
	return false;
}

CFile* Duplicate(){return NULL;}
DWORD GetPosition(){return 0;}
LONG Seek(LONG lOff, UINT nFrom){return 0;}
void SetLength(DWORD dwNewLen){}
DWORD GetLength(){return 0;}
void LockRange(DWORD dwPos, DWORD dwCount){}
void UnlockRange(DWORD dwPos, DWORD dwCount){}
void Flush(){}
void Abort(){}


Any input would be much appreciated

Mike Ellertson
GeneralRe: using CArchive with CBlockingSocket class Pin
Mikey_E25-Aug-03 8:30
professionalMikey_E25-Aug-03 8:30 
GeneralProblem with MFC create control for component Pin
tongc25-Aug-03 7:13
tongc25-Aug-03 7:13 
GeneralSHGetFileInfo Pin
Member 50856725-Aug-03 7:02
Member 50856725-Aug-03 7:02 
GeneralRe: SHGetFileInfo Pin
David Crow25-Aug-03 8:06
David Crow25-Aug-03 8:06 
GeneralRe: SHGetFileInfo Pin
Member 50856726-Aug-03 2:36
Member 50856726-Aug-03 2:36 
GeneralCommit to Disk Pin
jmf31415925-Aug-03 6:40
jmf31415925-Aug-03 6:40 
GeneralRe: Commit to Disk Pin
Neville Franks25-Aug-03 10:43
Neville Franks25-Aug-03 10:43 
GeneralRe: Commit to Disk Pin
jmf31415925-Aug-03 11:43
jmf31415925-Aug-03 11:43 
GeneralRe: Commit to Disk Pin
Neville Franks25-Aug-03 12:03
Neville Franks25-Aug-03 12:03 
GeneralRe: Commit to Disk Pin
parths25-Aug-03 15:25
parths25-Aug-03 15:25 
GeneralGibberish code Pin
dog_spawn25-Aug-03 15:06
dog_spawn25-Aug-03 15:06 
QuestionApplication-Close/Minimize effect, where? Pin
Exim25-Aug-03 6:39
Exim25-Aug-03 6:39 
AnswerRe: Application-Close/Minimize effect, where? Pin
Mikey_E25-Aug-03 10:16
professionalMikey_E25-Aug-03 10:16 
GeneralAutosrolling in an CEdit Pin
Bateman25-Aug-03 6:07
Bateman25-Aug-03 6:07 
Generalrefference a pointer to another process !!! Pin
mr200325-Aug-03 5:46
mr200325-Aug-03 5:46 
GeneralRe: refference a pointer to another process !!! Pin
valikac25-Aug-03 5:54
valikac25-Aug-03 5:54 
GeneralRe: refference a pointer to another process !!! Pin
Babayan Hovhannes26-Aug-03 0:04
Babayan Hovhannes26-Aug-03 0:04 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.