[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
about g++ 3.0
From: |
PeterPan |
Subject: |
about g++ 3.0 |
Date: |
Mon, 25 Jun 2001 22:26:30 +0800 |
hi, 2 problems:
1. All the document I saw told me iostream::overflow(int ch) should
return non-EOF on success,
but the code in g++ 3.0 assumed that it return ch (the input), did the
standard changed ??
in ostream.tcc line 353:
template<typename _CharT, typename _Traits>
basic_ostream<_CharT, _Traits>&
basic_ostream<_CharT, _Traits>::put(char_type __c)
{
sentry __cerb(*this);
if (__cerb)
{
int_type __put = rdbuf()->sputc(__c);
//--------------------------------------------------------------------------
-------
if (__put != traits_type::to_int_type(__c))
//--------------------------------------------------------------------------
------- //sputc should return the input on success, it's ok
this->setstate(ios_base::badbit);
}
return *this;
}
in streambuf.tcc line 95:
template<typename _CharT, typename _Traits>
basic_streambuf<_CharT, _Traits>::int_type
basic_streambuf<_CharT, _Traits>::
sputc(char_type __c)
{
int_type __ret;
if (_M_out_buf_size())
{
*_M_out_cur = __c;
_M_out_cur_move(1);
__ret = traits_type::to_int_type(__c);
}
else
__ret = this->overflow(traits_type::to_int_type(__c));
//==========================================================================
===============
// must overflow() return the input on success? not just a non-EOF value ??
return __ret;
}
2. I can't use filebuf to read data properly from a socket:
#include <iostream>
#include <iomanip>
#include <sys/types.h>
#include <sys/socket.h>
#include <fstream>
#include <unistd.h>
using namespace std;
int main(void)
{
int fds[2];
socketpair(AF_UNIX, SOCK_STREAM,0,fds);
perror("socketpair");
FILE *fp=fdopen(fds[0],"r+");
assert(fp!=NULL);
write(fds[1],"hahahoho\n",sizeof("hahahoho\n"));
string data;
// filebuf fbuf(fp,ios::in|ios::out,0); //all following 3 method not
work
// filebuf fbuf(fp,ios::in|ios::out,1);
filebuf fbuf(fp,ios::in|ios::out);
//peterpan test
char buf[2048];
cerr<<"test read ...";
//int n=fbuf.sgetn(buf,2048);
int n=fbuf.sbumpc();
while(n!=EOF&&n!='\n'){
cerr<<char(n);
n=fbuf.sbumpc();
} //should ouput "hahahoho"
//cerr<<"test read: "<<n<<' '<<string(buf,n)<<endl;
} //can't pass this test means
can't use the fbuf in a iostream
//fbuf.pubsetbuf(NULL,0);
perror("get fbuf");
//fstream conn (connfd);
iostream conn(&fbuf);
cerr<<"get data..."<<endl;
std::getline (conn, data);
cerr<<data<<endl;
}
Regards.
Guo Xuesong