本文整理汇总了C++中Sock::put方法的典型用法代码示例。如果您正苦于以下问题:C++ Sock::put方法的具体用法?C++ Sock::put怎么用?C++ Sock::put使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Sock
的用法示例。
在下文中一共展示了Sock::put方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1:
int
CCBListener::ReverseConnected(Stream *stream)
{
Sock *sock = (Sock *)stream;
ClassAd *msg_ad = (ClassAd *)daemonCore->GetDataPtr();
ASSERT( msg_ad );
if( sock ) {
daemonCore->Cancel_Socket( sock );
}
if( !sock || !sock->is_connected() ) {
ReportReverseConnectResult(msg_ad,false,"failed to connect");
}
else {
// The reverse-connect protocol is designed to look like a
// raw cedar command, in case the thing we are connecting
// to is a cedar command socket.
sock->encode();
int cmd = CCB_REVERSE_CONNECT;
if( !sock->put(cmd) ||
!msg_ad->put( *sock ) ||
!sock->end_of_message() )
{
ReportReverseConnectResult(msg_ad,false,"failure writing reverse connect command");
}
else {
((ReliSock*)sock)->isClient(false);
daemonCore->HandleReqAsync(sock);
sock = NULL; // daemonCore took ownership of sock
ReportReverseConnectResult(msg_ad,true);
}
}
delete msg_ad;
if( sock ) {
delete sock;
}
decRefCount(); // we incremented ref count when setting up callback
return KEEP_STREAM;
}
示例2: main
//.........这里部分代码省略.........
dprintf(D_FULLDEBUG,"locating collector %s...\n", collector->name());
if(!collector->locate()) {
fprintf(stderr,"couldn't locate collector: %s\n",collector->error());
had_error = true;
continue;
}
dprintf(D_FULLDEBUG,"collector is %s located at %s\n",
collector->hostname(),collector->addr());
sock = NULL;
ClassAd *ad;
int success_count = 0;
int failure_count = 0;
ads.Rewind();
while( (ad=ads.Next()) ) {
// If there's no "MyAddress", generate one..
if( !ad->Lookup( ATTR_MY_ADDRESS ) ) {
MyString tmp;
tmp.formatstr( "<%s:0>", my_ip_string() );
ad->Assign( ATTR_MY_ADDRESS, tmp.Value() );
}
if ( use_tcp ) {
if( !sock ) {
sock = collector->startCommand(command,Stream::reli_sock,20);
}
else {
// Use existing connection.
sock->encode();
sock->put(command);
}
} else {
// We must open a new UDP socket each time.
delete sock;
sock = collector->startCommand(command,Stream::safe_sock,20);
}
int result = 0;
if ( sock ) {
result += ad->put( *sock );
result += sock->end_of_message();
}
if ( result != 2 ) {
fprintf(stderr,"failed to send classad to %s\n",collector->addr());
had_error = true;
failure_count++;
delete sock;
sock = NULL;
continue;
}
if( with_ack ) {
sock->decode();
int ok = 0;
if( !sock->get(ok) || !sock->end_of_message() ) {
fprintf(stderr,"failed to get ack from %s\n",collector->addr());
had_error = true;
failure_count++;
delete sock;
sock = NULL;
continue;
}
示例3: if
//.........这里部分代码省略.........
}
else {
usage(argv[0]);
}
}
//----------------------------------------------------------
// Get info on our negotiator
Daemon negotiator(DT_NEGOTIATOR, NULL, (pool != "") ? pool.c_str() : NULL);
if (!negotiator.locate()) {
fprintf(stderr, "%s: Can't locate negotiator in %s\n",
argv[0], (pool != "") ? pool.c_str() : "local pool");
exit(1);
}
if (SetPrio) { // set priority
char* tmp;
if( ! (tmp = strchr(argv[SetPrio+1], '@')) ) {
fprintf( stderr,
"%s: You must specify the full name of the submittor you wish\n",
argv[0] );
fprintf( stderr, "\tto update the priority of (%s or %s)\n",
"[email protected]", "[email protected]" );
exit(1);
}
float Priority=atof(argv[SetPrio+2]);
// send request
Sock* sock;
if( !(sock = negotiator.startCommand(SET_PRIORITY,
Stream::reli_sock, 0) ) ||
!sock->put(argv[SetPrio+1]) ||
!sock->put(Priority) ||
!sock->end_of_message()) {
fprintf( stderr, "failed to send SET_PRIORITY command to negotiator\n" );
exit(1);
}
sock->close();
delete sock;
printf("The priority of %s was set to %f\n",argv[SetPrio+1],Priority);
}
else if (SetFactor) { // set priority
char* tmp;
if( ! (tmp = strchr(argv[SetFactor+1], '@')) ) {
fprintf( stderr,
"%s: You must specify the full name of the submittor you wish\n",
argv[0] );
fprintf( stderr, "\tto update the priority of (%s or %s)\n",
"[email protected]", "[email protected]" );
exit(1);
}
float Factor=atof(argv[SetFactor+2]);
if (Factor<1) {
fprintf( stderr, "Priority factors must be greater than or equal to "
"1.\n");
exit(1);
}
// send request