本文整理汇总了C++中Sink::write方法的典型用法代码示例。如果您正苦于以下问题:C++ Sink::write方法的具体用法?C++ Sink::write怎么用?C++ Sink::write使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Sink
的用法示例。
在下文中一共展示了Sink::write方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: sinkThread
/*------------------------------------------------------------------------------
* The function for each thread.
* Read the presented data
*----------------------------------------------------------------------------*/
void
MultiThreadedConnector :: sinkThread( int ixSink )
{
ThreadData * threadData = &threads[ixSink];
Sink * sink = sinks[ixSink].get();
while ( running ) {
// wait for some data to become available
pthread_mutex_lock( &mutexProduce);
while ( running && threadData->isDone ) {
pthread_cond_wait( &condProduce, &mutexProduce);
}
if ( !running ) {
pthread_mutex_unlock( &mutexProduce);
break;
}
if ( threadData->accepting ) {
if ( sink->canWrite( 0, 0) ) {
try {
sink->write( dataBuffer, dataSize);
} catch ( Exception & e ) {
// something wrong. don't accept more data, try to
// reopen the sink next time around
threadData->accepting = false;
}
} else {
reportEvent( 4,
"MultiThreadedConnector :: sinkThread can't write ",
ixSink);
// don't care if we can't write
}
}
threadData->isDone = true;
pthread_cond_broadcast( &condProduce);
pthread_mutex_unlock( &mutexProduce);
if ( !threadData->accepting ) {
if ( reconnect ) {
// if we're not accepting, try to reopen the sink
try {
sink->close();
sink->open();
threadData->accepting = sink->isOpen();
} catch ( Exception & e ) {
// don't care, just try and try again
}
} else {
// if !reconnect, just stop the connector
running = false;
}
}
}
}
示例2: sendto
ssize_t BufferRefSource::sendto(Sink& sink)
{
if (pos_ == buffer_.size())
return 0;
ssize_t result = sink.write(buffer_.data() + pos_, buffer_.size() - pos_);
if (result > 0)
pos_ += result;
return result;
}
示例3: sendto
ssize_t FilterSource::sendto(Sink& sink)
{
if (buffer_.empty()) {
BufferSink input;
ssize_t rv = source_->sendto(input);
if (rv < 0 || (rv == 0 && !force_))
return rv;
buffer_ = (*filter_)(input.buffer().ref());
}
ssize_t result = sink.write(buffer_.data() + pos_, buffer_.size() - pos_);
if (result > 0) {
pos_ += result;
if (pos_ == buffer_.size()) {
pos_ = 0;
buffer_.clear();
}
}
return result;
}
示例4: Exception
/*------------------------------------------------------------------------------
* Log in to the IceCast2 server
*----------------------------------------------------------------------------*/
bool
IceCast2 :: sendLogin ( void ) throw ( Exception )
{
Sink * sink = getSink();
Source * source = getSocket();
const char * str;
char resp[STRBUF_SIZE];
unsigned int len;
unsigned int lenExpected;
if ( !source->isOpen() ) {
return false;
}
if ( !sink->isOpen() ) {
return false;
}
// send the request, a string like:
// "SOURCE <mountpoint> ICE/1.0"
str = "SOURCE /";
sink->write( str, strlen( str));
str = getMountPoint();
sink->write( str, strlen( str));
str = " HTTP/1.0";
sink->write( str, strlen( str));
// send the content type, Ogg Vorbis
str = "\nContent-type: ";
sink->write( str, strlen( str));
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: ";
//.........这里部分代码省略.........
示例5: 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;
}
示例6: do_write
std::streamsize do_write(const char* s, std::streamsize n) // virtual
{
return sink_.write(s, n);
}
示例7: 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();
//.........这里部分代码省略.........
示例8: 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));
}
//.........这里部分代码省略.........