destructlm
Hello folks. Does someone know why write to a socket buffer at the full speed of a while loop generate a lot of data loss on client side, and when i insert an sleep(1) right after the server write function, client can read everything without data loss? (Both buffer have the same size)
Hirrolot
Ammar
See what I am doing here to handle such situation.
https://github.com/TeaInside/simple_file_transfer/blob/master/users/ammarfaizi2/client.c#L221-L288
destructlm
destructlm
destructlm
Ammar
Can you explain the step where data is lost ? I dind completely understand it!
Ok here.
Every socket has its own buffer in the kernel space. You can set the size with setsockopt() syscall.
When you write to socket buffer, the kernel copies the data you write from user space to kernel space, then it returns. The data is still in the kernel buffer.
Next you do write again, but the buffer in the kernel has not been flushed yet, because it is still waiting for network. So it must save the past write operation data you did.
But when the buffer is almost full, the kernel will only copy partial bytes. And then it informs you via return value how many bytes are written.
In this case, you will lose unwritten data if you don't resend the rest bytes.
Ammar
For example:
ssize_t ret;
ret = write(fd, buffer, 1024);
To check whether buffer is completely processed, you need to check that ret == 1024.
If it is less than 1024, then you need to resend the unwritten bytes.
Ammar
Ammar
Of course, the same thing happens on server side.
destructlm
Ok, i think i got it. So the solution is:
if ret <1024
Then: write(fd, buffer+red, buffer_size - red)
Ammar
Ammar
When you got EAGAIN, the return value will be -1.
destructlm
Ive inserted a simple header in the first 256bytes, so it need to garantee that it will arrive in the right positions of the client's buffer.
Jasur Fozilov 🐳
/get ides
Ammar
Ammar
If you use SOCK_DGRAM, it is a bit harder to recover from the above situation.
destructlm
SOCK_STREAM
Ammar
SOCK_STREAM
Alright, you can guarantee with that header.
Hirrolot
SOCK_STREAM
Then check for the returned value of write
Hirrolot
I.e. how many bytes have been written
Ammar
Plus, you have more people to answer.
destructlm
destructlm
I will send here, for sure it is a better choice!
H
Thanks ☺️
Siyolise
Hi guys
If u do have mql4 course
Pls share
Dede
Any C++ freelancer in here?
Dede
I need a pair programmer to work on a gig.
Dede
Sorry, I waited a few minutes but didn’t get any feedback. I hired someone else. Maybe next time!
Pavel
I want to write some benchmarks for my project, for example I have complex containers and I want to measure how much time it takes to add/remove stuff in these containers on average in specific situations, to then see a trend if these times will become worse at some point of development.
Which frameworks would you suggest, to write such benchmarks?
Anonymous
Golden
Hi people
Golden
Is c++ is good for arduino
Golden
Or there is better than it
Mazen
Golden
B121065_Swoyam Siddharth Nayak
string strmulti(string s1, string s2){
string str="";
string mask=s2;
while(s2!=""){
int i=1;
int a=stoi(s1);
int b=stoi(s2.substr((s2.size()-1), 1));
if(s2==mask){
str=to_string(a*b);
s2.erase(s2.size()-1);
i++;
}
else{
string temp=to_string(a*b*pow(10,i));
string mask2=str;
int tmp=0;
str="";
while(temp!="" || mask2!=""){
str=to_string((stoi(temp.substr(temp.size()-1))+stoi(mask2.substr(mask2.size()-1))+tmp)%10)+str;
tmp=(stoi(temp.substr(temp.size()-1))+stoi(mask2.substr(mask2.size()-1))+tmp)/10;
temp.erase(temp.size()-1);
mask2.erase(mask2.size()-1);
}
i++;
}
s2.erase(s2.size()-1);
}
return str
}
Is this is correct for string multiplication????
Anonymous
Anonymous
B121065_Swoyam Siddharth Nayak
https://www.geeksforgeeks.org/multiply-large-numbers-represented-as-strings/
i mean to multiple large numbers represented as strings
olli
B121065_Swoyam Siddharth Nayak
Mar!o
Is there a way to use a different index type for std::variant?
By default it's int AFAIK which is 4 bytes and too much for my needs.
I would like to use a byte std::uint8_t as index and pack the structure tightly to save more memory...
Golden
Pavel
Except for writing my own variant?!
How?
I'm looking into MSVC implementation and it seems like they are choosing the type of the index depending on the amount of types of the variant, but it's not exposed to the user
https://pastebin.com/PxM3zDb4
Mar!o
Pavel
Pavel
I mean maybe there are still gaps between them to align the pointer to be the most effective
Mar!o
Can it be related to alignment/packing?
Yeah it is - the whole structure is padded to 16 bytes which is okay in most cases
but in my case it takes 29 GB of RAM to store it because it's over 1 billion entries 😂
I've already compressed some pointers using 32-bit indices
but it would still be a big win to save 4 or 6 bytes...
Pavel
Pavel
But I've never used it myself, so have no idea how it should work
Mar!o
Pavel
Mar!o
:(
yeah :/
I will probably enroll my own variant
Anonymous
Guys please for those who have an idea about assembly language programming in the IAS machine, how do I store the results of multiplying two 40 bits numbers in the IAS memory and how must I divide to get a float in the IAS machine?
Shvmtz
function definition inside the main() in C. Is this supported by all compilers ?
mito
In C++,
Should I use ,
std::cout<<"Hello\n";
Or
std::cout<<"Hello"<<std::endl;
Or does it really matter ? Is there any difference?
Nameful
std::endl does more stuff
Nameful
It makes a newline and flushes stdout. \n just makes a newline
Dima
bruh
Nameful
So it depends on what you need. If you are writing a lot of data and performance is critical don't use endl
mito
Dima
Ammar
Papa
#include<iostream>
using namespace std;
int main()
{
int A[2][3]={{2,5,9},{7,3,6}};
int B[2][3]={{6,3,4},{9,5,2}};
int C[2][3];
for(int i=0;i<2;i++)
{
for(int j=0;j<3;j++)
{
C[i][j]=A[i][j] +B[i][j];
}
}
for(int i=0;i<2;i++)
{
for(int j=0;j<3;j++)
{ cout<<C[i][j];
}cout<<endl;
}
}
Papa
can anyone tell what is the mistake in this code
Nameful
what's this meme code
Hanz
my eyes hurt
Papa
#include<iostream>
using namespace std;
int main()
{
int A[2][3]={{2,5,9},{7,3,6}};
int B[2][3]={{6,3,4},{9,5,2}};
int C[2][3];
for(int i=0;i<2;i++)
{
for(int j=0;j<3;j++)
{
C[i][j]=A[i][j] +B[i][j];
}
}
for(int i=0;i<2;i++)
{
for(int j=0;j<3;j++)
{ cout<<C[i][j];
}cout<<endl;
}
}
Pls anyone
LJ
Hii
Anonymous
Pls anyone
You tell here what's the error you got when you compile/ ran.
Papa
LJ
Pls help me do you have any suggestion how to get the transmuted grade and print the equivalent grade?