I am using libcurl for a small program that gets data from an input url. But i sometimes get an error from the pErrorBuffer like:
Failed writing to body (something != somethingelse)
What does this mean? I mean in what situation is this error created?
It means your write callback didn't return the same number of bytes as was passed into it!
Related
I am using POCO 1.6.0. I am trying to write a service that receives a JSON message on a raw socket and parses it.
However, the only way that POCO's parser seems to work is to take an entire string as input, and either return the parsed result, or throw a "Syntax error" exception.
So this means I have to re-parse the whole message each time a new byte arrives on the socket; and also there is no way of distinguishing between an actual syntax error versus it just being an incomplete message so far.
The parseChar function looks nice but it is private. Is there any way to have the parser parse some of a message and remain in that state so that I can resume parsing by passing more data?
Also, is there any way to distinguish actual syntax errors from incomplete messages (and preferably get feedback about the exact nature of the syntax error).
Pseudocode:
Poco::JSON::Parser parser;
std::string input_buffer;
for(;;)
{
// (append byte(s) from socket into input_buffer)
// (return failure if this read times out after 5 seconds)
parser.reset();
try
{
parser.parse(input_buffer);
break;
}
catch(Poco::Exception &e)
{
// (abort, but we don't know if data incomplete or data malformed
}
}
Note: I realize that this problem could be mooted by having the client frame the entire message as described in this thread, however I was hoping to make things as simple as possible for the client by just having a correctly-formed packet be sufficient to define a frame (method 5 of that question).
There currently is no way to do either of the things you'd like to do. However, they are both reasonable requests and doable, so this was put on the TODO list for one of the upcoming releases.
I have written a small c++ program that takes some input files and runs some ffmpeg processes on them (via the 'system()' function). I would like to add to that program some code to delete the original files but I need to be sure that the ffmpeg commands executed properly and with no errors. How can I get my c++ program to check if the system() function it used executed properly?
According to the documentation for system
If command is not a null pointer, the value returned depends on the
system and library implementations, but it is generally expected to be
the status code returned by the called command, if supported.
In other words:
if(system("mycommand") != 0)
{
cout << "mycommand failed..." << endl;
}
or something like that. [Obviously assuming that "mycommand" is defined to give a result code of 0 if successfull - most things do, but there are exceptions].
If you use 'perror(errno)' it automatically prints the error to the standard error output-stream. Is there a way to get the value that would be printed without printing it?
You can use one of the strerror functions for that. They'll retrieve the error message without printing it.
I am trying to load an image using SHLoadImageFile,but its returning invalid handle.
I am puzzled where the fault is.Because the path given to SHLoadImageFile is absolutely fine.
The question title currently is "SHLoadImage is returning error code 6". But SHLoadImage return is a handle, not an error code. So perhaps this means that you have called GetLastError?
If so, then error code 6 is defined in <winerror.h> as
//
// MessageId: ERROR_INVALID_HANDLE
//
// MessageText:
//
// The handle is invalid.
//
#define ERROR_INVALID_HANDLE 6L
The documentation does not however say anything about SHLoadImage setting the last error code, so perhaps this is something from earlier in the execution. Try using SetLastError to set the last error code to 0 before calling SHLoadImage.
For more specific advice you need to include more specific information, like showing the code with the "absolutely fine" path. If it really is, perhaps the file doesn't exist. Or is not a valid image.
Cheers & hth.,
I'm trying to read the install path for an application, and I'm baffled at the behaviour I'm getting. First, here's the code that didn't work (formatted it a little so it doesn't take up a huge line):
LONG status = RegQueryValueEx(
hkRegistry,
"InstallPath",
0,
®Type, (LPBYTE)installPath,
®Size );
if (status == ERROR_SUCCESS) {
// Handle success.
}
I realized that it was failing on the call to RegQueryValueEx, so I decided to probe the return value by throwing it within an exception by adding:
else {
throw Exception( status );
}
But then... the code started to work and the call to RegQueryValueEx succeeded. I've been able to repeat this behaviour as long as I throw something within the else. If I comment out the body of the else, the error returns.
Edit: Okay, I tried calling MessageBox instead of an exception and I get the same behaviour. If I comment it out, it stops working again.
Is there a rational explanation for this?
It's possible that the buffer for installPath is too small compared to the value contained in regSize (which must be initialized to the size of the buffer).
If installPath is a stack-allocated value I suspect that it is overflown, causing the value of status to get overwritten.