本文整理汇总了C++中Sock::end_of_message方法的典型用法代码示例。如果您正苦于以下问题:C++ Sock::end_of_message方法的具体用法?C++ Sock::end_of_message怎么用?C++ Sock::end_of_message使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Sock
的用法示例。
在下文中一共展示了Sock::end_of_message方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: startCommand
bool
DCStartd::drainJobs(int how_fast,bool resume_on_completion,char const *check_expr,char const *start_expr,std::string &request_id)
{
std::string error_msg;
ClassAd request_ad;
Sock *sock = startCommand( DRAIN_JOBS, Sock::reli_sock, 20 );
if( !sock ) {
formatstr(error_msg,"Failed to start DRAIN_JOBS command to %s",name());
newError(CA_FAILURE,error_msg.c_str());
return false;
}
request_ad.Assign(ATTR_HOW_FAST,how_fast);
request_ad.Assign(ATTR_RESUME_ON_COMPLETION,resume_on_completion);
if( check_expr ) {
request_ad.AssignExpr(ATTR_CHECK_EXPR,check_expr);
}
if( start_expr ) {
request_ad.AssignExpr(ATTR_START_EXPR,start_expr);
}
if( !putClassAd(sock, request_ad) || !sock->end_of_message() ) {
formatstr(error_msg,"Failed to compose DRAIN_JOBS request to %s",name());
newError(CA_FAILURE,error_msg.c_str());
delete sock;
return false;
}
sock->decode();
ClassAd response_ad;
if( !getClassAd(sock, response_ad) || !sock->end_of_message() ) {
formatstr(error_msg,"Failed to get response to DRAIN_JOBS request to %s",name());
newError(CA_FAILURE,error_msg.c_str());
delete sock;
return false;
}
response_ad.LookupString(ATTR_REQUEST_ID,request_id);
bool result = false;
int error_code = 0;
response_ad.LookupBool(ATTR_RESULT,result);
if( !result ) {
std::string remote_error_msg;
response_ad.LookupString(ATTR_ERROR_STRING,remote_error_msg);
response_ad.LookupInteger(ATTR_ERROR_CODE,error_code);
formatstr(error_msg,
"Received failure from %s in response to DRAIN_JOBS request: error code %d: %s",
name(),error_code,remote_error_msg.c_str());
newError(CA_FAILURE,error_msg.c_str());
delete sock;
return false;
}
delete sock;
return true;
}
示例2:
void
CCBServer::ForwardRequestToTarget( CCBServerRequest *request, CCBTarget *target )
{
Sock *sock = target->getSock();
ClassAd msg;
msg.Assign( ATTR_COMMAND, CCB_REQUEST );
msg.Assign( ATTR_MY_ADDRESS, request->getReturnAddr() );
msg.Assign( ATTR_CLAIM_ID, request->getConnectID() );
// for easier debugging
msg.Assign( ATTR_NAME, request->getSock()->peer_description() );
MyString reqid_str;
CCBIDToString( request->getRequestID(), reqid_str);
msg.Assign( ATTR_REQUEST_ID, reqid_str );
sock->encode();
if( !msg.put( *sock ) || !sock->end_of_message() ) {
dprintf(D_ALWAYS,
"CCB: failed to forward request id %lu from %s to target "
"daemon %s with ccbid %lu\n",
request->getRequestID(),
request->getSock()->peer_description(),
target->getSock()->peer_description(),
target->getCCBID());
RequestFinished( request, false, "failed to forward request to target" );
return;
}
// Now wait for target to respond (HandleRequestResultsMsg).
// We will get the response next time we poll the socket.
// To get a faster response, we _could_ register the socket
// now, if it has not already been registered.
}
示例3: putClassAd
bool
putClassAdAndEOM(Sock & sock, classad::ClassAd &ad)
{
if (sock.type() != Stream::reli_sock)
{
return putClassAd(&sock, ad) && sock.end_of_message();
}
ReliSock & rsock = static_cast<ReliSock&>(sock);
Selector selector;
selector.add_fd(sock.get_file_desc(), Selector::IO_WRITE);
int timeout = sock.timeout(0); sock.timeout(timeout);
timeout = timeout ? timeout : 20;
selector.set_timeout(timeout);
if (!putClassAd(&sock, ad, PUT_CLASSAD_NON_BLOCKING))
{
return false;
}
int retval = rsock.end_of_message_nonblocking();
while (true) {
if (rsock.clear_backlog_flag()) {
Py_BEGIN_ALLOW_THREADS
selector.execute();
Py_END_ALLOW_THREADS
if (selector.timed_out()) {THROW_EX(RuntimeError, "Timeout when trying to write to remote host");}
} else if (retval == 1) {
示例4: GetMyProxyPasswordFromSchedD
int GetMyProxyPasswordFromSchedD (int cluster_id, int proc_id,
char ** password)
{
// This might seem not necessary, but it IS
// For some reason you can't just pass cluster_id to sock->code() directly!!!!
int cluster, proc;
cluster = cluster_id;
proc = proc_id;
dprintf ( D_FULLDEBUG, " GetMyProxyPasswordFromSchedD %d, %d\n", cluster_id, proc_id);
// Get At Schedd
Daemon schedd( DT_SCHEDD );
if( ! schedd.locate() ) {
dprintf( D_ALWAYS, "GetMyProxyPasswordFromSchedD: Can't find address of local schedd\n" );
return FALSE;
}
// Start command
Sock* sock;
if (!(sock = schedd.startCommand( GET_MYPROXY_PASSWORD, Stream::reli_sock, 0))) {
dprintf( D_ALWAYS, "GetMyProxyPasswordFromSchedD: Could not connect to local schedd\n" );
return FALSE;
}
sock->encode();
if (!sock->code (cluster) || !sock->code(proc)) {
dprintf( D_ALWAYS, "GetMyProxyPasswordFromSchedD: Could not encode clusterId, procId\n" );
return FALSE;
}
sock->end_of_message();
sock->decode();
if (!sock->code (*password)) {
dprintf( D_ALWAYS, "GetMyProxyPasswordFromSchedD: Can't retrieve password\n" );
return FALSE;
}
sock->end_of_message();
sock->close();
delete sock;
return TRUE;
}
示例5: credd
void
MachAttributes::credd_test()
{
// Attempt to perform a NOP on our CREDD_HOST. This will test
// our ability to authenticate with DAEMON-level auth, and thus
// fetch passwords. If we succeed, we'll advertise the CREDD_HOST
char *credd_host = param("CREDD_HOST");
if (credd_host == NULL) {
if (m_local_credd != NULL) {
free(m_local_credd);
m_local_credd = NULL;
}
return;
}
if (m_local_credd != NULL) {
if (strcmp(m_local_credd, credd_host) == 0) {
free(credd_host);
return;
}
else {
free(m_local_credd);
m_local_credd = NULL;
m_last_credd_test = 0;
}
}
time_t now = time(NULL);
double thresh = (double)param_integer("CREDD_TEST_INTERVAL", 300);
if (difftime(now, m_last_credd_test) > thresh) {
Daemon credd(DT_CREDD);
if (credd.locate()) {
Sock *sock = credd.startCommand(CREDD_NOP, Stream::reli_sock, 20);
if (sock != NULL) {
sock->decode();
if (sock->end_of_message()) {
m_local_credd = credd_host;
}
}
}
m_last_credd_test = now;
}
if (credd_host != m_local_credd) {
free(credd_host);
}
}
示例6:
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;
}
示例7: if
//.........这里部分代码省略.........
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
Sock* sock;
if( !(sock = negotiator.startCommand(SET_PRIORITYFACTOR,
示例8: queryAd
// process ads from the collector, handing each to the callback
// callback will return 'false' if it took ownership of the ad.
QueryResult CondorQuery::
processAds (bool (*callback)(void*, ClassAd *), void* pv, const char * poolName, CondorError* errstack /*= NULL*/)
{
Sock* sock;
QueryResult result;
ClassAd queryAd(extraAttrs);
if ( !poolName ) {
return Q_NO_COLLECTOR_HOST;
}
// contact collector
Daemon my_collector( DT_COLLECTOR, poolName, NULL );
if( !my_collector.locate() ) {
// We were passed a bogus poolName, abort gracefully
return Q_NO_COLLECTOR_HOST;
}
// make the query ad
result = getQueryAd (queryAd);
if (result != Q_OK) return result;
if (IsDebugLevel(D_HOSTNAME)) {
dprintf( D_HOSTNAME, "Querying collector %s (%s) with classad:\n",
my_collector.addr(), my_collector.fullHostname() );
dPrintAd( D_HOSTNAME, queryAd );
dprintf( D_HOSTNAME, " --- End of Query ClassAd ---\n" );
}
int mytimeout = param_integer ("QUERY_TIMEOUT",60);
if (!(sock = my_collector.startCommand(command, Stream::reli_sock, mytimeout, errstack)) ||
!putClassAd (sock, queryAd) || !sock->end_of_message()) {
if (sock) {
delete sock;
}
return Q_COMMUNICATION_ERROR;
}
// get result
sock->decode ();
int more = 1;
while (more)
{
if (!sock->code (more)) {
sock->end_of_message();
delete sock;
return Q_COMMUNICATION_ERROR;
}
if (more) {
ClassAd * ad = new ClassAd;
if( !getClassAd(sock, *ad) ) {
sock->end_of_message();
delete ad;
delete sock;
return Q_COMMUNICATION_ERROR;
}
if (callback(pv, ad)) {
delete ad;
}
}
}
sock->end_of_message();
// finalize
sock->close();
delete sock;
return (Q_OK);
}
示例9: 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;
}
// ack protocol does not allow for multiple updates,
// so close the socket now
delete sock;
sock = NULL;
}
success_count++;
}
if( sock ) {
CondorVersionInfo const *ver = sock->get_peer_version();
if( !ver || ver->built_since_version(7,7,3) ) {
// graceful hangup so the collector knows we are done
sock->encode();
command = DC_NOP;
sock->put(command);
sock->end_of_message();
}
delete sock;
sock = NULL;
}
printf("Sent %d of %d ad%s to %s.\n",
success_count,
success_count + failure_count,
success_count+failure_count == 1 ? "" : "s",
collector->name());
}
delete collectors;
return (had_error)?1:0;
}
示例10: startCommand
bool
DCShadow::updateJobInfo( ClassAd* ad, bool insure_update )
{
if( ! ad ) {
dprintf( D_FULLDEBUG,
"DCShadow::updateJobInfo() called with NULL ClassAd\n" );
return false;
}
if( ! shadow_safesock && ! insure_update ) {
shadow_safesock = new SafeSock;
shadow_safesock->timeout(20); // years of research... :)
if( ! shadow_safesock->connect(_addr) ) {
dprintf( D_ALWAYS, "updateJobInfo: Failed to connect to shadow "
"(%s)\n", _addr );
delete shadow_safesock;
shadow_safesock = NULL;
return false;
}
}
ReliSock reli_sock;
Sock* tmp;
bool result;
if( insure_update ) {
// For now, if we have to ensure that the update gets
// there, we use a ReliSock (TCP).
reli_sock.timeout(20); // years of research... :)
if( ! reli_sock.connect(_addr) ) {
dprintf( D_ALWAYS, "updateJobInfo: Failed to connect to shadow "
"(%s)\n", _addr );
return false;
}
result = startCommand( SHADOW_UPDATEINFO, (Sock*)&reli_sock );
tmp = &reli_sock;
} else {
result = startCommand( SHADOW_UPDATEINFO, (Sock*)shadow_safesock );
tmp = shadow_safesock;
}
if( ! result ) {
dprintf( D_FULLDEBUG,
"Failed to send SHADOW_UPDATEINFO command to shadow\n" );
if( shadow_safesock ) {
delete shadow_safesock;
shadow_safesock = NULL;
}
return false;
}
if( ! putClassAd(tmp, *ad) ) {
dprintf( D_FULLDEBUG,
"Failed to send SHADOW_UPDATEINFO ClassAd to shadow\n" );
if( shadow_safesock ) {
delete shadow_safesock;
shadow_safesock = NULL;
}
return false;
}
if( ! tmp->end_of_message() ) {
dprintf( D_FULLDEBUG,
"Failed to send SHADOW_UPDATEINFO EOM to shadow\n" );
if( shadow_safesock ) {
delete shadow_safesock;
shadow_safesock = NULL;
}
return false;
}
return true;
}
示例11: schedd
//.........这里部分代码省略.........
if (p == 'N' || p == 'O') {
// authentication will not happen since no security negotiation will occur
can_auth = false;
}
}
paramer = SecMan::getSecSetting ("SEC_%s_AUTHENTICATION", CLIENT_PERM);
if (paramer != NULL) {
char p = toupper(paramer[0]);
free(paramer);
if (p == 'N') {
// authentication will not happen since client doesn't allow it.
can_auth = false;
}
}
// authentication will not happen since server probably doesn't allow it.
// on the off chance that someone's config manages to trick us, leave an
// undocumented knob as a last resort to disable our inference.
if (param_boolean("CONDOR_Q_INFER_SCHEDD_AUTHENTICATION", true)) {
paramer = SecMan::getSecSetting ("SEC_%s_AUTHENTICATION", READ);
if (paramer != NULL) {
char p = toupper(paramer[0]);
free(paramer);
if (p == 'N') {
can_auth = false;
}
}
paramer = SecMan::getSecSetting ("SCHEDD.SEC_%s_AUTHENTICATION", READ);
if (paramer != NULL) {
char p = toupper(paramer[0]);
free(paramer);
if (p == 'N') {
can_auth = false;
}
}
}
if (!can_auth) {
dprintf (D_ALWAYS, "detected that authentication will not happen. falling back to QUERY_JOB_ADS without authentication.\n");
}
DCSchedd schedd(host);
int cmd = QUERY_JOB_ADS;
if (want_authentication && can_auth && (useFastPath > 2)) {
cmd = QUERY_JOB_ADS_WITH_AUTH;
}
Sock* sock;
if (!(sock = schedd.startCommand(cmd, Stream::reli_sock, connect_timeout, errstack))) return Q_SCHEDD_COMMUNICATION_ERROR;
classad_shared_ptr<Sock> sock_sentry(sock);
if (!putClassAd(sock, request_ad) || !sock->end_of_message()) return Q_SCHEDD_COMMUNICATION_ERROR;
dprintf(D_FULLDEBUG, "Sent classad to schedd\n");
int rval = 0;
do {
ad = new ClassAd();
if ( ! getClassAd(sock, *ad) || ! sock->end_of_message()) {
rval = Q_SCHEDD_COMMUNICATION_ERROR;
break;
}
dprintf(D_FULLDEBUG, "Got classad from schedd.\n");
long long intVal;
if (ad->EvaluateAttrInt(ATTR_OWNER, intVal) && (intVal == 0))
{ // Last ad.
sock->close();
dprintf(D_FULLDEBUG, "Ad was last one from schedd.\n");
std::string errorMsg;
if (ad->EvaluateAttrInt(ATTR_ERROR_CODE, intVal) && intVal && ad->EvaluateAttrString(ATTR_ERROR_STRING, errorMsg))
{
if (errstack) errstack->push("TOOL", intVal, errorMsg.c_str());
rval = Q_REMOTE_ERROR;
}
if (psummary_ad && rval == 0) {
std::string val;
if (ad->LookupString(ATTR_MY_TYPE, val) && val == "Summary") {
ad->Delete(ATTR_OWNER); // remove the bogus owner attribute
*psummary_ad = ad; // return the final ad, because it has summary information
ad = NULL; // so we don't delete it below.
}
}
break;
}
// Note: According to condor_q.h, process_func() will return false if taking
// ownership of ad, so only delete if it returns true, else set to NULL
// so we don't delete it here. Either way, next set ad to NULL since either
// it has been deleted or will be deleted later by process_func().
if (process_func(process_func_data, ad)) {
delete ad;
}
ad = NULL;
} while (true);
// Make sure ad is not leaked no matter how we break out of the above loop.
delete ad;
return rval;
}
示例12: GetRequest
void
CCBServer::HandleRequestResultsMsg( CCBTarget *target )
{
// Reply from target daemon about whether it succeeded in
// connecting to the requested client.
Sock *sock = target->getSock();
ClassAd msg;
sock->decode();
if( !msg.initFromStream( *sock ) || !sock->end_of_message() ) {
// disconnect
dprintf(D_FULLDEBUG,
"CCB: received disconnect from target daemon %s "
"with ccbid %lu.\n",
sock->peer_description(), target->getCCBID() );
RemoveTarget( target );
return;
}
int command = 0;
if( msg.LookupInteger( ATTR_COMMAND, command ) && command == ALIVE ) {
SendHeartbeatResponse( target );
return;
}
target->decPendingRequestResults();
bool success = false;
MyString error_msg;
MyString reqid_str;
CCBID reqid;
MyString connect_id;
msg.LookupBool( ATTR_RESULT, success );
msg.LookupString( ATTR_ERROR_STRING, error_msg );
msg.LookupString( ATTR_REQUEST_ID, reqid_str );
msg.LookupString( ATTR_CLAIM_ID, connect_id );
if( !CCBIDFromString( reqid, reqid_str.Value() ) ) {
MyString msg_str;
msg.sPrint(msg_str);
dprintf(D_ALWAYS,
"CCB: received reply from target daemon %s with ccbid %lu "
"without a valid request id: %s\n",
sock->peer_description(),
target->getCCBID(),
msg_str.Value());
RemoveTarget( target );
return;
}
CCBServerRequest *request = GetRequest( reqid );
if( request && request->getSock()->readReady() ) {
// Request socket must have just closed. To avoid noise in
// logs when we fail to write to it, delete the request now.
RemoveRequest( request );
request = NULL;
}
char const *request_desc = "(client which has gone away)";
if( request ) {
request_desc = request->getSock()->peer_description();
}
if( success ) {
dprintf(D_FULLDEBUG,"CCB: received 'success' from target daemon %s "
"with ccbid %lu for "
"request %s from %s.\n",
sock->peer_description(),
target->getCCBID(),
reqid_str.Value(),
request_desc);
}
else {
dprintf(D_FULLDEBUG,"CCB: received error from target daemon %s "
"with ccbid %lu for "
"request %s from %s: %s\n",
sock->peer_description(),
target->getCCBID(),
reqid_str.Value(),
request_desc,
error_msg.Value());
}
if( !request ) {
if( success ) {
// expected: the client has gone away; it got what it wanted
return;
}
dprintf( D_FULLDEBUG,
"CCB: client for request %s to target daemon %s with ccbid "
"%lu disappeared before receiving error details.\n",
reqid_str.Value(),
sock->peer_description(),
target->getCCBID());
return;
}
if( connect_id != request->getConnectID() ) {
MyString msg_str;
msg.sPrint(msg_str);
//.........这里部分代码省略.........
示例13: schedd
int
CondorQ::fetchQueueFromHostAndProcessV2(const char *host,
const char *constraint,
StringList &attrs,
condor_q_process_func process_func,
void * process_func_data,
int connect_timeout,
CondorError *errstack)
{
classad::ClassAdParser parser;
classad::ExprTree *expr = NULL;
parser.ParseExpression(constraint, expr);
if (!expr) return Q_INVALID_REQUIREMENTS;
classad::ExprList *projList = new classad::ExprList();
if (!projList) return Q_INTERNAL_ERROR;
attrs.rewind();
const char *attr;
while ((attr = attrs.next())) {
classad::Value value; value.SetStringValue(attr);
classad::ExprTree *entry = classad::Literal::MakeLiteral(value);
if (!entry) return Q_INTERNAL_ERROR;
projList->push_back(entry);
}
classad::ClassAd ad;
ad.Insert(ATTR_REQUIREMENTS, expr);
classad::ExprTree *projTree = static_cast<classad::ExprTree*>(projList);
ad.Insert(ATTR_PROJECTION, projTree);
DCSchedd schedd(host);
Sock* sock;
if (!(sock = schedd.startCommand(QUERY_JOB_ADS, Stream::reli_sock, connect_timeout, errstack))) return Q_SCHEDD_COMMUNICATION_ERROR;
classad_shared_ptr<Sock> sock_sentry(sock);
if (!putClassAd(sock, ad) || !sock->end_of_message()) return Q_SCHEDD_COMMUNICATION_ERROR;
dprintf(D_FULLDEBUG, "Sent classad to schedd\n");
do {
classad_shared_ptr<compat_classad::ClassAd> ad(new ClassAd());
if (!getClassAd(sock, *ad.get())) return Q_SCHEDD_COMMUNICATION_ERROR;
if (!sock->end_of_message()) return Q_SCHEDD_COMMUNICATION_ERROR;
dprintf(D_FULLDEBUG, "Got classad from schedd.\n");
long long intVal;
if (ad->EvaluateAttrInt(ATTR_OWNER, intVal) && (intVal == 0))
{ // Last ad.
sock->close();
dprintf(D_FULLDEBUG, "Ad was last one from schedd.\n");
std::string errorMsg;
if (ad->EvaluateAttrInt(ATTR_ERROR_CODE, intVal) && intVal && ad->EvaluateAttrString(ATTR_ERROR_STRING, errorMsg))
{
if (errstack) errstack->push("TOOL", intVal, errorMsg.c_str());
return Q_REMOTE_ERROR;
}
break;
}
(*process_func) (process_func_data, ad);
} while (true);
return 0;
}
示例14: readHistoryRemote
// Read history from a remote schedd
static void readHistoryRemote(classad::ExprTree *constraintExpr)
{
printHeader();
if(longformat && use_xml) {
std::string out;
AddClassAdXMLFileHeader(out);
printf("%s\n", out.c_str());
}
classad::ClassAd ad;
classad::ExprList *projList(new classad::ExprList());
classad::ExprTree *projTree = static_cast<classad::ExprTree*>(projList);
ad.Insert(ATTR_PROJECTION, projTree);
ad.Insert(ATTR_REQUIREMENTS, constraintExpr);
ad.InsertAttr(ATTR_NUM_MATCHES, specifiedMatch <= 0 ? -1 : specifiedMatch);
DCSchedd schedd(g_name.size() ? g_name.c_str() : NULL, g_pool.size() ? g_pool.c_str() : NULL);
if (!schedd.locate(Daemon::LOCATE_FOR_LOOKUP)) {
fprintf(stderr, "Unable to locate remote schedd (name=%s, pool=%s).\n", g_name.c_str(), g_pool.c_str());
exit(1);
}
Sock* sock;
if (!(sock = schedd.startCommand(QUERY_SCHEDD_HISTORY, Stream::reli_sock, 0))) {
fprintf(stderr, "Unable to send history command to remote schedd;\n"
"Typically, either the schedd is not responding, does not authorize you, or does not support remote history.\n");
exit(1);
}
classad_shared_ptr<Sock> sock_sentry(sock);
if (!putClassAd(sock, ad) || !sock->end_of_message()) {
fprintf(stderr, "Unable to send request to remote schedd; likely a server or network error.\n");
exit(1);
}
while (true) {
compat_classad::ClassAd ad;
if (!getClassAd(sock, ad)) {
fprintf(stderr, "Failed to recieve remote ad.\n");
exit(1);
}
long long intVal;
if (ad.EvaluateAttrInt(ATTR_OWNER, intVal) && (intVal == 0)) { // Last ad.
if (!sock->end_of_message()) {
fprintf(stderr, "Unable to close remote socket.\n");
}
sock->close();
std::string errorMsg;
if (ad.EvaluateAttrInt(ATTR_ERROR_CODE, intVal) && intVal && ad.EvaluateAttrString(ATTR_ERROR_STRING, errorMsg)) {
fprintf(stderr, "Error %lld: %s\n", intVal, errorMsg.c_str());
exit(intVal);
}
if (ad.EvaluateAttrInt("MalformedAds", intVal) && intVal) {
fprintf(stderr, "Remote side had parse errors on history file");
exit(1);
}
if (!ad.EvaluateAttrInt(ATTR_NUM_MATCHES, intVal) || (intVal != matchCount)) {
fprintf(stderr, "Client and server do not agree on number of ads sent;\n"
"Indicates lost network packets or an internal error\n");
exit(1);
}
break;
}
matchCount++;
printJob(ad);
}
if(longformat && use_xml) {
std::string out;
AddClassAdXMLFileFooter(out);
printf("%s\n", out.c_str());
}
}
示例15: my_collector
// fetch all ads from the collector that satisfy the constraints
QueryResult CondorQuery::
fetchAds (ClassAdList &adList, const char *poolName, CondorError* errstack)
{
Sock* sock;
int more;
QueryResult result;
ClassAd queryAd(extraAttrs), *ad;
if ( !poolName ) {
return Q_NO_COLLECTOR_HOST;
}
// contact collector
Daemon my_collector( DT_COLLECTOR, poolName, NULL );
if( !my_collector.locate() ) {
// We were passed a bogus poolName, abort gracefully
return Q_NO_COLLECTOR_HOST;
}
// make the query ad
result = getQueryAd (queryAd);
if (result != Q_OK) return result;
if( IsDebugLevel( D_HOSTNAME ) ) {
dprintf( D_HOSTNAME, "Querying collector %s (%s) with classad:\n",
my_collector.addr(), my_collector.fullHostname() );
queryAd.dPrint( D_HOSTNAME );
dprintf( D_HOSTNAME, " --- End of Query ClassAd ---\n" );
}
int mytimeout = param_integer ("QUERY_TIMEOUT",60);
if (!(sock = my_collector.startCommand(command, Stream::reli_sock, mytimeout, errstack)) ||
!queryAd.put (*sock) || !sock->end_of_message()) {
if (sock) {
delete sock;
}
return Q_COMMUNICATION_ERROR;
}
// get result
sock->decode ();
more = 1;
while (more)
{
if (!sock->code (more)) {
sock->end_of_message();
delete sock;
return Q_COMMUNICATION_ERROR;
}
if (more) {
ad = new ClassAd;
if( !ad->initFromStream(*sock) ) {
sock->end_of_message();
delete ad;
delete sock;
return Q_COMMUNICATION_ERROR;
}
adList.Insert (ad);
}
}
sock->end_of_message();
// finalize
sock->close();
delete sock;
return (Q_OK);
}