|
sorry, but how can i give a back_inserter or an ostringstream as a parameter in recv call? I could not figure it out.
modified 29-Aug-18 21:01pm.
|
|
|
|
|
You can eliminate double copying if having an std::vector instead of a std::string is OK with you. Of course, copying is still done when resizing the container (but this is unavoidable):
std::vector<char> v(1);
size_t extra_space=0;
int len=0;
do
{
if(!extra_space){
v.resize(v.size()+512);
extra_space=511;
}
char * p=&v[0]+v.size()-extra_space-1;
len= recv(socket, p, extra_space, 0);
extra_space-=len;
}while (len > 0);
v[v.size()-extra_space-1]='0';
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
Thank you very much.
But, I use a few string operations that i believe is not available in vector. I have to look at the rest of my code to see whether vector can indeed be used.
|
|
|
|
|
Andrei Alexandrescu wrote a A Policy-Based basic_string Implementation[^] that's basically a drop-in replacement of std::string s. One of the incarnations of this class, namely that which uses VectorStringStorage as its Storage template parameter, uses a std::vector as back-end storage, so you can use it like I suggested in my latter post and yet have all the facilities std::string s come equipped with.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
It is a realy pity that Mr. Alexandrescu doesn't seem to be doing anything much with his Loki library. It is a very impressive body of work, but he almost seems to have abandoned it. I know there is a group on Sourceforge doing some work on it, but Andrei appears to be invisible.
And wouldn't it be great if we could use it with VC6, not that thats his fault of course. This is one of the few reasons for moving to VC7.
Neville Franks, Author of ED for Windows. www.getsoft.com
|
|
|
|
|
VC7.1 you mean? VC7 can't for christs sake even handle PTS!
|
|
|
|
|
Mike Nordell wrote:
VC7.1 you mean? VC7 can't for christs sake even handle PTS!
I reckon I should know what PTS is but ...???
Is there such as beast as VC7.1?
STL, Boost, Loki et.all are all wonderfull stuff for our toolkit, but without compilers that are able to use them all we can do is sit and drool and wait impatiently.
Neville Franks, Author of ED for Windows. www.getsoft.com
|
|
|
|
|
I reckon I should know what PTS is but ...???
Partial Template Specialization. For instance:
template <typename A> class MyTemplateClass{...};
template <> MyTemplateClass<int>{...};
template <typename A> MyTemplateClass<A *>{...};
Is there such as beast as VC7.1?
This is an internal version codenamed Everett (I think) which allegedly supports PTS. MS says it'll be released by February 2003.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
Joaquín M López Muñoz wrote:
I reckon I should know what PTS is but ...???
Partial Template Specialization. For instance:
Yes of course. I knew it would be something obvious.
Joaquín M López Muñoz wrote:
Is there such as beast as VC7.1?
This is an internal version codenamed Everett (I think) which allegedly supports PTS. MS says it'll be released by February 2003.
I thought the folks working on Loki at Sourceforge had a complete imlementation for VC7, and I thought Loki required PTS, but it seems like I'm wrong somewhere along the line.
It is really surprising that a company the size of MS is taking so long to get issues like PTS handled in their compiler.
Neville Franks, Author of ED for Windows. www.getsoft.com
|
|
|
|
|
The group on Sourceforge is working on porting Loke to VC6 --take a look at the project CVS respository. I don't know how much has been ported so far.
Some of the concepts discussed in Loki are implemented under various forms in Boost, notably functors. I think Boost is a more reliable library to use: continuous support, has been ported to many more platforms, appears more stable.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
Last time I looked only a very small part of Loki had been implemented for VC6 and I was told that their wasn't much more they could do because of the VC6 compiler limitations we all know about.
I bought "Modern C++ Design" a few months back and got quite excited reading it, only to be let down by the inability to actually use it.
It sure would be great if someone would write a nice big reference + examples book for Boost.
I'll follow your suggestion and focus on Boost, and I guess STLPort.
Neville Franks, Author of ED for Windows. www.getsoft.com
|
|
|
|
|
Forgive me if this is a dumb question I am very new to thread programming.. I have read a bunch of the articles here on code project about threads.. I want to do the following in a thread but the problem is that I need to pass the thread or start the thread with 3 vars "CString strPath, CString strDns, int nPort"... heres the snip of code that I am using to send a file.
I have tried to create a thread to do the following but it crashes every time..
Anyone have any ideas how I can do the following inside a thread??
CFile myFile(strPath, CFile::modeRead | CFile::typeBinary);
CSocket sSocket;
sSocket.Create();
int iConnect = sSocket.Connect(strDns,nPort);
if(iConnect == SOCKET_ERROR)
{
AfxMessageBox("Communication Error!");
}
else
{
CSocketFile sf(&sSocket);
CArchive ar(&sf, CArchive::store);
DWORD length = myFile.GetLength();
char *data = new char[length];
myFile.Read(data, length);
ar << myFile.GetFileName();
ar << length;
ar.Write(data,length);
myFile.Close();
delete[] data;
}
Thanks!
|
|
|
|
|
I do not see where you create a worker thread. Where does the thread begin?
Use a worker thread.
Kuphryn
|
|
|
|
|
I have tried a few different ways to create the thread but all result in the same type of errors.. here is one example that i used, but i cant pass the thread any variables.. I can just start it and stop it..
Header..
static UINT run(LPVOID p);
void run();
volatile BOOL running;
void CMyView::TransferFile()
{
running = TRUE;
AfxBeginThread(run, this);
}
UINT CMyView::run(LPVOID p)
{
CMyView * me = (CMyView *)p;
me->run();
return 0;
}
void CMyView::run()
{
running = FALSE;
}
|
|
|
|
|
Consider a global thread function. Otherwise, make run() a static function.
Kuphryn
|
|
|
|
|
If I make run() static.. how can I access member functions from CMainFrame? Or is that a "no-no"?
|
|
|
|
|
You may access the static member function via :: operator.
Kuphryn
|
|
|
|
|
This looks ok to me and is the sort of thing I do in ED. I wouldn't have called both functions run though, but that is besides the point. Also don't use the old C style casts in C++. I assume the view exists for the duration of the thread function. Where precisely does it crash?
Neville Franks, Author of ED for Windows. www.getsoft.com
|
|
|
|
|
it crashes on the Create() of the CSocket object.. I just implemented a CWinThread class and I am trying to do the same thing with in that class because someone stated that I need a UI thread instead of a worker thread.. I guess CSocket needs a Message Pump.. but now I am still having the same problems it still crashes on the Create function.. I posted another question in the forum because I changed the code so much.. I have a feeling that the CSocket needs to be attached to the thread but I am having no luck.. Any ideas?
|
|
|
|
|
I'm afraid I can't help much with CSocket as I've never used it. That said if you look in the debugger at the error it should give you a very good idea of what the problem is. Looking at the MFC code my guess is something in CAsyncSocket::AttachHandle() is ASSERTing.
I'd be surprised if there wasn't code which used CSocket in a thread here on CP. Maybe spend some time looking at the articles in the relevant section.
Neville Franks, Author of ED for Windows. www.getsoft.com
|
|
|
|
|
Thanks for all the suggestions.. I am going to trace the error codes for CSOcket and see what type of error i am getting from the create function.. I tried to create the socket in my main thread and pass the handle to the thread but the socket in the thread gives me a invalid socket.. anyway, I'll do some more testing, its probably just something dumb on my part..
Thanks!
Rob
|
|
|
|
|
// setowner.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <iostream.h>
#include <windows.h>
#include <tchar.h>
#define ErrorHandler(s) _ErrorHandler(s, __FILE__, __LINE__)
void _ErrorHandler(LPCSTR lpszLocation, LPCTSTR lpszSrcFile, UINT nSrcLine)
{
LPVOID lpMsgBuf;
DWORD dwError = GetLastError();
FormatMessageA(
FORMAT_MESSAGE_ALLOCATE_BUFFER |
FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_IGNORE_INSERTS,
NULL,
dwError,
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
(LPSTR) &lpMsgBuf,
0,
NULL );
// Process any inserts in lpMsgBuf.
cout<<"ERROR @ "<
|
|
|
|
|
ive seen a lot of application create .exe from the main application, and not just one, i mean after a serie of choices u can do that.
To make myself clear, im not talking about adding a single exe to the ressource and reading it than writing it in a .exe file.
I meant after a series of tests or choices i want to be able to generate a custom .exe
Hope this is clear enough, and thanks in advance for any tip or help!
Johnny
|
|
|
|
|
See this[^] for informations about PE file format (Win32 exe).
Pavel
Sonork 100.15206
|
|
|
|
|
Thanks a lot, ill read through it!
Papa
while (TRUE)
Papa.WillLove ( Bebe ) ;
|
|
|
|