Re: Huge File read and send via socket
This is a multi-part message in MIME format.
------=_NextPart_000_0016_01C85F3D.E88EB710
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
I don't know what you mean, but fopen and such function you used can not =
arrange bigsize file over 2G, so you will use another function just like =
CreateFile to deal with those file over 2G!
"Ganesh" <gvijayaratnam@gmail.com> wrote in message =
news:%23KfMenYXIHA.4448@TK2MSFTNGP03.phx.gbl...
Hi all,
I am new to c++ and socket programming, I have a situvation that my =
function have to a binary read ( whole file as 1 chunk ) and keep the =
buffer, and send the buffrer via socket by chunk by chunk as user =
specified. I have written a code sample, but I am not getting the =
correct out out.
can some one pls look in to the code and fix it ?
FILE *fp23 = fopen( "c:\\hpfile.prn", "rb" );
fseek (fp23 , 0 , SEEK_END);
int m_jobSize = ftell (fp23);
rewind (fp23);
char* m_buffer = new char[m_jobSize+1];
int m_result = fread( m_buffer, 1, m_jobSize, fp23 );
///////////////////////////////////////////////
int BytesIndex = 0;
while( bufsize > 0)
{
// Send some bytes
if ( bufsize < (unsigned long)iSendStatus )
{
iSendStatus = send(*sock, &m_buffer[BytesIndex], bufsize, 0); // =
Socket is of type
//
// Call Back Function
//
set += iSendStatus;
ptr(jobid,set);
if ( iSendStatus != bufsize )
{
cpError = SocketErrorHandler();
return cpError;
}
}
else
{
iSendStatus = send(*sock, &m_buffer[BytesIndex], chunkSize, 0); =
// Socket is of type
//
// Call Back Function
//
set += iSendStatus;
ptr(jobid,set);
if ( iSendStatus != chunkSize )
{
cpError = SocketErrorHandler();
return cpError;
}
}
// Update buffer and counter
if ( bufsize < (unsigned long)iSendStatus )
{
bufsize -= bufsize;
BytesIndex += bufsize;
}
else
{
bufsize -= iSendStatus;
BytesIndex +=iSendStatus;
}
//////////////////////////////
regards
Ganesh
------=_NextPart_000_0016_01C85F3D.E88EB710
Content-Type: text/html;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; =
charset=iso-8859-1">
<META content="MSHTML 6.00.6000.16587" name=GENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=#ffffff>
<DIV><FONT face=Arial size=2>I don't know what you mean, but <FONT
face="Courier New">fopen and such function you used can not arrange =
bigsize file
over 2G, so you will use another function just like CreateFile to deal =
with
those file over 2G!</FONT></FONT></DIV>
<BLOCKQUOTE dir=ltr
style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; =
BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
<DIV>"Ganesh" <<A
=
href="mailto:gvijayaratnam@gmail.com">gvijayaratnam@gmail.com</A>> =
wrote in
message <A
=
href="news:%23KfMenYXIHA.4448@TK2MSFTNGP03.phx.gbl">news:%23KfMenYXIHA.=
4448@TK2MSFTNGP03.phx.gbl</A>...</DIV>
<DIV><FONT face=Arial size=2>Hi all,</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2>I am new to c++ and socket =
programming, I have a
situvation that my function have to a binary read ( whole file as 1 =
chunk )
and keep the buffer, and send the buffrer via socket by chunk by =
chunk as
user specified. I have written a code sample, but I am not getting the =
correct
out out.</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2>can some one pls look in to the code =
and fix it
?</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face="Courier New" size=2>FILE *fp23 = fopen( =
"c:\\hpfile.prn",
"rb" );</FONT></DIV>
<DIV><FONT face="Courier New" size=2></FONT> </DIV>
<DIV><FONT face="Courier New" size=2>fseek (fp23 , 0 , =
SEEK_END);<BR>int
m_jobSize = ftell (fp23);<BR>rewind (fp23);</FONT></DIV>
<DIV><FONT face="Courier New" size=2></FONT> </DIV>
<DIV><FONT face="Courier New" size=2>char* m_buffer = new
char[m_jobSize+1];</FONT></DIV>
<DIV><FONT face="Courier New" size=2></FONT> </DIV>
<DIV><FONT face="Courier New" size=2>int m_result = fread( =
m_buffer, 1,
m_jobSize, fp23 );</FONT></DIV>
<DIV><FONT face="Courier New" size=2></FONT> </DIV>
<DIV><FONT face="Courier New" size=2></FONT> </DIV>
<DIV><FONT face="Courier New"
size=2>///////////////////////////////////////////////</FONT></DIV>
<DIV><FONT face="Courier New"></FONT> </DIV>
<DIV><FONT face="Courier New" size=2> int BytesIndex = 0; =
</FONT></DIV>
<DIV><FONT face="Courier New"></FONT> </DIV>
<DIV><FONT face="Courier New" size=2> while( bufsize >
0)<BR> {</FONT></DIV>
<DIV><FONT face="Courier New"></FONT> </DIV>
<DIV><FONT face="Courier New" size=2> // Send some
bytes<BR> if ( bufsize < (unsigned long)iSendStatus
)<BR> {<BR> iSendStatus = send(*sock,
&m_buffer[BytesIndex], bufsize, 0); // Socket is of
=
type<BR> <BR> //<BR> /=
/
Call Back Function<BR> //<BR> set =
+=
=
iSendStatus;<BR> ptr(jobid,set);<BR> </=
FONT></DIV>
<DIV><FONT face="Courier New"></FONT> </DIV>
<DIV><FONT face="Courier New" size=2> if ( =
iSendStatus !=
bufsize )<BR> {<BR> cpError =
=
SocketErrorHandler();<BR> return
cpError;<BR> }</FONT></DIV>
<DIV><FONT face="Courier New"></FONT> </DIV>
<DIV><FONT face="Courier New"
=
size=2> }<BR> else<BR> {<BR> &nbs=
p; iSendStatus
= send(*sock, &m_buffer[BytesIndex], chunkSize, 0); // Socket is =
of
type</FONT></DIV>
<DIV><FONT face="Courier New"></FONT> </DIV>
<DIV><FONT face="Courier New"
size=2> //<BR> // Call Back
Function<BR> //<BR> set +=
iSendStatus;<BR> ptr(jobid,set);</FONT></DIV>
<DIV><FONT face="Courier New"></FONT> </DIV><FONT size=2>
<DIV><BR><FONT face="Courier New"> if ( iSendStatus =
!=
chunkSize )<BR> {<BR> cpError =
=
SocketErrorHandler();<BR> return
=
cpError;<BR> }<BR> <BR> }</FONT></DIV>
<DIV><FONT face="Courier New"></FONT> </DIV>
<DIV><FONT face="Courier New"> // Update buffer and
counter<BR> if ( bufsize < (unsigned long)iSendStatus
)<BR> {<BR> bufsize -=
bufsize;<BR> BytesIndex +=
=
bufsize;<BR> }<BR> else<BR> {<BR> &=
nbsp; bufsize
-= iSendStatus; <BR> BytesIndex +=iSendStatus;
<BR> }</FONT></DIV>
<DIV><FONT face="Courier New"></FONT> </DIV>
<DIV><BR><FONT
face="Courier =
New">//////////////////////////////<BR></FONT></FONT></DIV>
<DIV><FONT face=Arial size=2>regards</FONT></DIV>
<DIV><FONT face=Arial size=2>Ganesh</FONT></DIV>
<DIV><FONT face=Arial =
size=2></FONT> </DIV></BLOCKQUOTE></BODY></HTML>
------=_NextPart_000_0016_01C85F3D.E88EB710--