Probable reasons for Illegal seek in socket programming [closed] - c++

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 years ago.
Improve this question
I have received following error while sending data.
send:29-Illegal seek
Please explain the probable reasons for it. I am new to socket programming. Thanks in advance.
CHAR datasend[200];
DOUBLE64 fTime=0.0;
LONG32 sent_bytes=0;
while(TRUE)
{
memset(datasend,0,200);
fTime=getTime();
sprintf(datasend,"0=%.0lf ",fTime);
sent_bytes = send ( isockfd, datasend, strlen(datasend),0);
logDebug1("Pulse is %s and data bytes is %d",datasend,strlen(datasend));
if(sent_bytes <= 0)
{
logPError("send");
logTimestamp("Closing socket\n");
close(isockfd);
return NULL;
}
sleep(25);
}

You're not interpreting the right error because of the intervening logDebug1 call.
You have a send that returns something <= 0 and possibly an errno that you could inspect
You print something (logDebug1) which likely clobbers errno
You do some sort of perror which interprets the clobbered errno
What you want to do instead is check if sentBytes < 0, perror immediately and then maybe print more debugging stuff if you want.

Related

How to get available space on a network drive in c++? [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 1 year ago.
Improve this question
I tried using std::filesystem::space(dir) but with no luck -> it cannot determine available disk space, sets it to uintmax.
auto info = std::filesystem::space("K:\\Dir");
if(info.available == static_cast<uintmax_t>(-1))
{
std::cout << "Error occurred!\n";
}
K:\Dir does indeed exist. And this snippet prints Error occurred for my drive mounted on K:.
If you want to get the free space you need to try
const std::filesystem::space_info spaceInfo = std::filesystem::space(dir);
cout << static_cast<std::intmax_t>(spaceInfo.free) << endl;
Here dir = "/path/to/dir/";
Refer cppreference

Why cout and cin would pop up error when I use ncurses..? [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 5 years ago.
Improve this question
Emmm...I am writing a code that it can read the user input immediately after user press the key...
and I found the code online:
initscr();
cbreak();
noecho();
scrollok(stdscr, TRUE);
nodelay(stdscr, TRUE);
while (true) {
if (getch() == 'g') {
printw("You pressed G\n");
}
napms(500);
printw("Running\n");
}
and it worked pretty well..then I turn to use cout to print what I read in getch()...
I am now confused how nucurse.h handle the cout or I mean standard I/O..?
initscr tells (n)curses to write to the standard output. However, ncurses buffers its writes separately from the cout stream (see for example Output buffering in the ncurses6 release notes), and flushes its output when told to refresh. getch does a refresh call as a side-effect. There aren't other refresh calls in your example.
ncurses (like SVr4 curses) sets its input to raw mode, but that aspect is not related to your problem with cout.

Arduino double command [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 6 years ago.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Improve this question
I'm trying to find a way for my Arduino to recognize some of the commands I'm attempting to send over serial (via Raspberry Pi)
I'm come as far as to detect 2 commands, but I'm stuck at my last.
To give a little bit more detail, I have my fingerprint scanner (GT-511C3) connected, and the library installed that will make it work.
That said, with the first 2 commands consist the verifying of fingerprints to ID (which works great) and the enrolling of fingerprints to new ID's (also work great) these parts of the script are triggered by the respective ASCII code "0" and "1".
My last, and problematic command "2" to remove an ID, is where I'm seeking help with.
Here's the code I'm currently working with:
if(ser == '2'){
while(val2 == 0){
char val3 = 0;
delay(10);
Serial.println("Type the ID to be deleted");
delay(2500);
fps.DeleteID(Serial.read());
val3 == Serial.read();
delay(10);
Serial.println("Deleted ID:");
Serial.print(val3);
delay(10);
val2 = 1;
}
}
I'm attempting to send the ASCII code "2" over Raspberry Pi through serial to the Arduino, followed by the ID that needs to be removed. It triggers after the command "2" is send, but refuses to read the ID and as such, I'm unable to finish it.
Any help or insight would really be appreciated.
val3 == Serial.read(); should be val3 = Serial.read();. You have an extra = which turns it into a useless comparison.

How to explain the strange output by "puts" in c++? [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 years ago.
Improve this question
I am reading a piece of code written by others, there is one line like this:
cout << "Data Loaded" << endl;
it seems nothing strange, however, the actually output is:
[18607330327, 18790481919] [19144201237, 19327352831] [20754813973, 20937965567] [21291684885, 21474836479] [21474836482, 21653864362] [22011707392, 22190735274] [23622320128, 23801348010] [24159191040, 24338218922] [27197264917, 27204255743] [27205653525, 27212644351] [27230819349, 27230959453] [27233615872, 27235153757] [30064771072, 30067638186] [30073159680, 30076026794] [30098325504, 30098440106] [30098456576, 30098536200] Data Loaded
where does the extra output come from? if I comment that line, then, nothing is output.
I then include the <cstdio> and replace that line by puts("Data Loaded"), still, the extra info get printed.
cout is a buffered output stream, and endl not only creates a new line, it also flushes the buffer. Without the flushing of the buffer it might happen that you do not see the output of a previous cout.

Ncurses: movement [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 4 years ago.
Improve this question
I have a problem with programming movement using C++ and Ncurses.
I'm programming a pacman and the main problem is, that I just want last pressed key in time period.
When I use usleep, it saves every key pressed during sleeping and then it's working with that in the order.
Thanks for ideas.
What did you try?
Something like this should work, if I understood correctly what you try to achieve:
int t = your_delay;
while (t --> 0)
{
sleep(1);
c = getch();
}
If you really need to time it down to the microsecond, this might not be the best approach, but if you can have some tolerance, this should be enough.
Are you in no-delay mode? If so, this might work:
usleep(your_delay);
last_key = ERR;
while ( (key=getch()) != ERR ) {
last_key = key;
}
// "last_key" now holds most recent key, if there was one, else ERR