本文整理汇总了C++中Sink::flush方法的典型用法代码示例。如果您正苦于以下问题:C++ Sink::flush方法的具体用法?C++ Sink::flush怎么用?C++ Sink::flush使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Sink
的用法示例。
在下文中一共展示了Sink::flush方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Exception
//.........这里部分代码省略.........
switch ( format ) {
case mp3:
str = "audio/mpeg";
break;
case oggVorbis:
str = "application/x-ogg";
break;
default:
throw Exception( __FILE__, __LINE__,
"unsupported stream format", format);
break;
}
sink->write( str, strlen( str));
// send the authentication info
str = "\nAuthorization: Basic ";
sink->write( str, strlen(str));
{
// send source:<password> encoded as base64
char * source = "source:";
const char * pwd = getPassword();
char * tmp = new char[Util::strLen(source) +
Util::strLen(pwd) + 1];
Util::strCpy( tmp, source);
Util::strCat( tmp, pwd);
char * base64 = Util::base64Encode( tmp);
delete[] tmp;
sink->write( base64, strlen(base64));
delete[] base64;
}
// send user agent info
str = "\nUser-Agent: DarkIce/" VERSION " (http://darkice.sourceforge.net/)";
sink->write( str, strlen( str));
// send the ice- headers
str = "\nice-bitrate: ";
sink->write( str, strlen( str));
if ( log10(getBitRate()) >= (STRBUF_SIZE-2) ) {
throw Exception( __FILE__, __LINE__,
"bitrate does not fit string buffer", getBitRate());
}
sprintf( resp, "%d", getBitRate());
sink->write( resp, strlen( resp));
str = "\nice-public: ";
sink->write( str, strlen( str));
str = getIsPublic() ? "1" : "0";
sink->write( str, strlen( str));
if ( getName() ) {
str = "\nice-name: ";
sink->write( str, strlen( str));
str = getName();
sink->write( str, strlen( str));
}
if ( getDescription() ) {
str = "\nice-description: ";
sink->write( str, strlen( str));
str = getDescription();
sink->write( str, strlen( str));
}
if ( getUrl() ) {
str = "\nice-url: ";
sink->write( str, strlen( str));
str = getUrl();
sink->write( str, strlen( str));
}
if ( getGenre() ) {
str = "\nice-genre: ";
sink->write( str, strlen( str));
str = getGenre();
sink->write( str, strlen( str));
}
str = "\n\n";
sink->write( str, strlen( str));
sink->flush();
// read the response, expected response begins with responseOK
lenExpected = Util::strLen( responseOK);
if ( (len = source->read( resp, STRBUF_SIZE-1)) < lenExpected ) {
return false;
}
resp[lenExpected] = 0;
if ( !Util::strEq( resp, responseOK) ) {
return false;
}
// suck anything that the other side has to say
while ( source->canRead( 0, 0) &&
(len = source->read( resp, STRBUF_SIZE-1)) );
return true;
}
示例2: Exception
/*------------------------------------------------------------------------------
* Log in to the ShoutCast server using the icy login scheme
*----------------------------------------------------------------------------*/
bool
ShoutCast :: sendLogin ( void ) throw ( Exception )
{
Sink * sink = getSink();
Source * source = getSocket();
const char * str;
char resp[STRBUF_SIZE];
unsigned int len;
if ( !source->isOpen() ) {
return false;
}
if ( !sink->isOpen() ) {
return false;
}
/* first line is the password in itself */
str = getPassword();
sink->write( str, strlen( str));
str = "\n";
sink->write( str, strlen( str));
sink->flush();
/* read the anticipated response: "OK" */
len = source->read( resp, STRBUF_SIZE);
reportEvent(8, "server response length: ", len);
reportEvent(8, "server response: ", resp);
if ( len < 2 || resp[0] != 'O' || resp[1] != 'K' ) {
return false;
}
/* suck anything that the other side has to say */
while ( source->canRead( 0, 0) &&
(len = source->read( resp, STRBUF_SIZE)) ) {
;
}
/* send the icy headers */
if ( getName() ) {
str = "icy-name:";
sink->write( str, strlen( str));
str = getName();
sink->write( str, strlen( str));
}
if ( getGenre() ) {
str = "\nicy-genre:";
sink->write( str, strlen( str));
str = getGenre();
sink->write( str, strlen( str));
}
str = "\nicy-pub:";
sink->write( str, strlen( str));
str = getIsPublic() ? "1" : "0";
sink->write( str, strlen( str));
str = "\nicy-br:";
sink->write( str, strlen( str));
if ( log10(getBitRate()) >= (STRBUF_SIZE-2) ) {
throw Exception( __FILE__, __LINE__,
"bitrate does not fit string buffer", getBitRate());
}
sprintf( resp, "%d", getBitRate());
sink->write( resp, strlen( resp));
if ( getUrl() ) {
str = "\nicy-url:";
sink->write( str, strlen( str));
str = getUrl();
sink->write( str, strlen( str));
}
if ( getIrc() ) {
str = "\nicy-irc:";
sink->write( str, strlen( str));
str = getIrc();
sink->write( str, strlen( str));
}
if ( getIcq() ) {
str = "\nicy-icq:";
sink->write( str, strlen( str));
str = getIcq();
sink->write( str, strlen( str));
}
if ( getAim() ) {
str = "\nicy-aim:";
sink->write( str, strlen( str));
str = getAim();
sink->write( str, strlen( str));
}
str = "\n\n";
sink->write( str, strlen( str));
sink->flush();
//.........这里部分代码省略.........
示例3: Exception
/*------------------------------------------------------------------------------
* Log in to the IceCast server
*----------------------------------------------------------------------------*/
bool
IceCast :: sendLogin ( void ) throw ( Exception )
{
Sink * sink = getSink();
Source * source = getSocket();
const char * str;
char resp[STRBUF_SIZE];
unsigned int len;
if ( !source->isOpen() ) {
return false;
}
if ( !sink->isOpen() ) {
return false;
}
/* send the request, a string like:
* "SOURCE <password> /<mountpoint>\n" */
str = "SOURCE ";
sink->write( str, strlen( str));
str = getPassword();
sink->write( str, strlen( str));
str = " /";
sink->write( str, strlen( str));
str = getMountPoint();
sink->write( str, strlen( str));
/* send the x-audiocast headers */
str = "\nx-audiocast-bitrate: ";
sink->write( str, strlen( str));
if ( log10(getBitRate()) >= (STRBUF_SIZE-2) ) {
throw Exception( __FILE__, __LINE__,
"bitrate does not fit string buffer", getBitRate());
}
sprintf( resp, "%d", getBitRate());
sink->write( resp, strlen( resp));
str = "\nx-audiocast-public: ";
sink->write( str, strlen( str));
str = getIsPublic() ? "1" : "0";
sink->write( str, strlen( str));
if ( getName() ) {
str = "\nx-audiocast-name: ";
sink->write( str, strlen( str));
str = getName();
sink->write( str, strlen( str));
}
if ( getDescription() ) {
str = "\nx-audiocast-description: ";
sink->write( str, strlen( str));
str = getDescription();
sink->write( str, strlen( str));
}
if ( getUrl() ) {
str = "\nx-audiocast-url: ";
sink->write( str, strlen( str));
str = getUrl();
sink->write( str, strlen( str));
}
if ( getGenre() ) {
str = "\nx-audiocast-genre: ";
sink->write( str, strlen( str));
str = getGenre();
sink->write( str, strlen( str));
}
if ( getRemoteDumpFile() ) {
str = "\nx-audiocast-dumpfile: ";
sink->write( str, strlen( str));
str = getRemoteDumpFile();
sink->write( str, strlen( str));
}
str = "\n\n";
sink->write( str, strlen( str));
sink->flush();
/* read the anticipated response: "OK" */
len = source->read( resp, STRBUF_SIZE);
if ( len < 2 || resp[0] != 'O' || resp[1] != 'K' ) {
return false;
}
/* suck anything that the other side has to say */
while ( source->canRead( 0, 0) &&
(len = source->read( resp, STRBUF_SIZE)) ) {
;
}
return true;
}
示例4: Exception
/*------------------------------------------------------------------------------
* Log in to the ShoutCast server using the icy login scheme
*----------------------------------------------------------------------------*/
bool
ShoutCast :: sendLogin ( void ) throw ( Exception )
{
Sink * sink = getSink();
Source * source = getSocket();
const char * str;
char resp[STRBUF_SIZE];
unsigned int len;
bool needsMountPoint = false;
const char * mountPoint = getMountPoint();
if ( !source->isOpen() ) {
return false;
}
if ( !sink->isOpen() ) {
return false;
}
// We will add SOURCE only if really needed: if the mountPoint is not null
// and is different of "/". This is to keep maximum compatibility with
// NullSoft Shoutcast server.
if (mountPoint != 0L
&& strlen(mountPoint) > 0 && 0 != strcmp("/", mountPoint)) {
needsMountPoint = true;
}
std::ostringstream os;
if (needsMountPoint) {
os << "SOURCE ";
}
/* first line is the password in itself */
os << getPassword();
os << "\n";
// send the mount point
if (needsMountPoint) {
os << " ";
if (strncmp("/", mountPoint, 1) != 0) {
os << "/";
}
os << mountPoint;
os << "\n";
}
str = os.str().c_str();
// Ok, now we send login which will be different of classical Shoutcast
// if mountPoint is not null and is different from "/" ...
sink->write( str, strlen( str));
sink->flush();
/* read the anticipated response: "OK" */
len = source->read( resp, STRBUF_SIZE);
reportEvent(8, "server response length: ", len);
reportEvent(8, "server response: ", resp);
if ( len < 2 || resp[0] != 'O' || resp[1] != 'K' ) {
return false;
}
/* suck anything that the other side has to say */
while ( source->canRead( 0, 0) &&
(len = source->read( resp, STRBUF_SIZE)) ) {
;
}
/* send the icy headers */
if ( getName() ) {
str = "icy-name:";
sink->write( str, strlen( str));
str = getName();
sink->write( str, strlen( str));
}
if ( getUrl() ) {
str = "\nicy-url:";
sink->write( str, strlen( str));
str = getUrl();
sink->write( str, strlen( str));
}
if ( getGenre() ) {
str = "\nicy-genre:";
sink->write( str, strlen( str));
str = getGenre();
sink->write( str, strlen( str));
}
if ( getIrc() ) {
str = "\nicy-irc:";
sink->write( str, strlen( str));
str = getIrc();
sink->write( str, strlen( str));
}
//.........这里部分代码省略.........