当前位置: 首页>>代码示例>>C++>>正文


C++ ConnectionState类代码示例

本文整理汇总了C++中ConnectionState的典型用法代码示例。如果您正苦于以下问题:C++ ConnectionState类的具体用法?C++ ConnectionState怎么用?C++ ConnectionState使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了ConnectionState类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: expectSenderSpecifier

bool AbstractCarrier::expectSenderSpecifier(ConnectionState& proto) {
    NetInt32 numberSrc;
    Bytes number((char*)&numberSrc,sizeof(NetInt32));
    int len = 0;
    YARP_SSIZE_T r = proto.is().readFull(number);
    if ((size_t)r!=number.length()) {
        YARP_DEBUG(Logger::get(),"did not get sender name length");
        return false;
    }
    len = NetType::netInt(number);
    if (len>1000) len = 1000;
    if (len<1) len = 1;
    // expect a string -- these days null terminated, but not in YARP1
    ManagedBytes b(len+1);
    r = proto.is().readFull(Bytes(b.get(),len));
    if ((int)r!=len) {
        YARP_DEBUG(Logger::get(),"did not get sender name");
        return false;
    }
    // add null termination for YARP1
    b.get()[len] = '\0';
    String s = b.get();
    proto.setRoute(proto.getRoute().addFromName(s));
    return true;
}
开发者ID:BRKMYR,项目名称:yarp,代码行数:25,代码来源:AbstractCarrier.cpp

示例2: readYarpInt

bool yarp::os::impl::UdpCarrier::expectReplyToHeader(ConnectionState& proto) {
    // I am the sender
    int myPort = proto.getStreams().getLocalAddress().getPort();
    ConstString myName = proto.getStreams().getLocalAddress().getHost();
    ConstString altName = proto.getStreams().getRemoteAddress().getHost();

    int altPort = readYarpInt(proto);

    if (altPort==-1) {
        return false;
    }

    DgramTwoWayStream *stream = new DgramTwoWayStream();
    yAssert(stream!=YARP_NULLPTR);

    proto.takeStreams(YARP_NULLPTR); // free up port from tcp
    bool ok =
        stream->open(Contact(myName,myPort),Contact(altName,altPort));
    if (!ok) {
        delete stream;
        return false;
    }
    proto.takeStreams(stream);
    return true;
}
开发者ID:giuliavezzani,项目名称:yarp,代码行数:25,代码来源:UdpCarrier.cpp

示例3:

// This is called when a connection is being established and returns an initialised ConnectionState instance.
ConnectionState *Network::ConnectionAccepted(tcp_pcb *pcb)
{
	ConnectionState *cs = freeConnections;
	if (cs == NULL)
	{
		platform->Message(HOST_MESSAGE, "Network::ConnectionAccepted() - no free ConnectionStates!\n");
		return NULL;
	}

	NetworkTransaction* r = freeTransactions;
	if (r == NULL)
	{
		platform->Message(HOST_MESSAGE, "Network::ConnectionAccepted() - no free transactions!\n");
		return NULL;
	}

	freeConnections = cs->next;
	cs->Init(pcb);

	r->Set(NULL, cs, connected);
	freeTransactions = r->next;
	AppendTransaction(&readyTransactions, r);

	return cs;
}
开发者ID:AltairResearch,项目名称:RepRapFirmware,代码行数:26,代码来源:Network.cpp

示例4: send_net_data

void send_net_data(JOCTET *data, int len, void *client) {
    dbg_printf("Send %d bytes\n", len);
    ConnectionState *p = (ConnectionState *)client;
    char hdr[1000];
    sprintf(hdr,"\n");
    const char *brk = "\n";
    if (hdr[1]=='\0') {
        brk = "\r\n";
    }
    dbg_printf("Using terminator %s\n",(hdr[1]=='\0')?"\\r\\n":"\\n");
    sprintf(hdr,"Content-Type: image/jpeg%s\
Content-Length: %d%s%s", brk, len, brk, brk);
    Bytes hbuf(hdr,strlen(hdr));
    p->os().write(hbuf);
    Bytes buf((char *)data,len);
    /*
      // add corruption now and then, for testing.
    static int ct = 0;
    ct++;
    if (ct==50) {
        printf("Adding corruption\n");
        buf.get()[0] = 'z';
        ct = 0;
    }
    */
    p->os().write(buf);
    sprintf(hdr,"%s--boundarydonotcross%s",brk,brk);
    Bytes hbuf2(hdr,strlen(hdr));
    p->os().write(hbuf2);

}
开发者ID:JoErNanO,项目名称:yarp,代码行数:31,代码来源:MjpegCarrier.cpp

示例5: expectSenderSpecifier

bool AbstractCarrier::expectSenderSpecifier(ConnectionState& proto)
{
    NetInt32 numberSrc;
    Bytes number((char*)&numberSrc, sizeof(NetInt32));
    int len = 0;
    YARP_SSIZE_T r = proto.is().readFull(number);
    if ((size_t)r!=number.length()) {
        YARP_DEBUG(Logger::get(), "did not get sender name length");
        return false;
    }
    len = NetType::netInt(number);
    if (len>1000) {
        len = 1000;
    }
    if (len<1) {
        len = 1;
    }
    ManagedBytes b(len+1);
    r = proto.is().readFull(Bytes(b.get(), len));
    if ((int)r!=len) {
        YARP_DEBUG(Logger::get(), "did not get sender name");
        return false;
    }
    ConstString s = b.get();
    Route route = proto.getRoute();
    route.setFromName(s);
    proto.setRoute(route);
    return true;
}
开发者ID:jgvictores,项目名称:yarp,代码行数:29,代码来源:AbstractCarrier.cpp

示例6: shouldInterpretRosMessages

bool XmlRpcCarrier::shouldInterpretRosMessages(ConnectionState& proto) {
    // We need to set the interpretRos flag, which controls
    // whether ROS-style admin messages are treated as
    // admin messages or data messages in YARP.
    // In the future, they should always be data messages.
    // For now, they should be admin messages for all ports
    // except ports tagged as corresponding to ros nodes.

    bool nodelike = false;
    Contactable *port = proto.getContactable();
    Property opt;
    if (port) {
        Property *pport = port->acquireProperties(true);
        if (pport) {
            opt = *pport;
        }
        port->releaseProperties(pport);
    }
    if (opt.check("node_like")) {
        nodelike = true;
    }

    Name n(proto.getRoute().getCarrierName() + "://test");
    ConstString rospass = n.getCarrierModifier("ros");
    interpretRos = !nodelike;
    if (rospass=="1"||rospass=="on") {
        interpretRos = true;
    }
    if (rospass=="0"||rospass=="off") {
        interpretRos = false;
    }
    return interpretRos;
}
开发者ID:JoErNanO,项目名称:yarp,代码行数:33,代码来源:XmlRpcCarrier.cpp

示例7:

bool yarp::os::impl::TextCarrier::expectSenderSpecifier(ConnectionState& proto)
{
    YARP_SPRINTF0(Logger::get(), debug, "TextCarrier::expectSenderSpecifier");
    Route route = proto.getRoute();
    route.setFromName(proto.is().readLine());
    proto.setRoute(route);
    return true;
}
开发者ID:ale-git,项目名称:yarp,代码行数:8,代码来源:TextCarrier.cpp

示例8: write

bool AbstractCarrier::write(ConnectionState& proto, SizedWriter& writer) {
    bool ok = sendIndex(proto,writer);
    if (!ok) {
        return false;
    }
    writer.write(proto.os());
    proto.os().flush();
    return proto.os().isOk();
}
开发者ID:BRKMYR,项目名称:yarp,代码行数:9,代码来源:AbstractCarrier.cpp

示例9: sendConnectionStateSpecifier

bool AbstractCarrier::sendConnectionStateSpecifier(ConnectionState& proto) {
    char buf[8];
    Bytes header((char*)&buf[0],sizeof(buf));
    OutputStream& os = proto.os();
    proto.getConnection().getHeader(header);
    os.write(header);
    os.flush();
    return os.isOk();
}
开发者ID:BRKMYR,项目名称:yarp,代码行数:9,代码来源:AbstractCarrier.cpp

示例10: DgramTwoWayStream

bool yarp::os::impl::McastCarrier::becomeMcast(ConnectionState& proto, bool sender) {
#ifndef YARP_HAS_ACE
    return false;
#else
    YARP_UNUSED(sender);
    DgramTwoWayStream *stream = new DgramTwoWayStream();
    yAssert(stream!=YARP_NULLPTR);
    Contact remote = proto.getStreams().getRemoteAddress();
    Contact local;
    local = proto.getStreams().getLocalAddress();
    bool test = true;
    //(yarp::NameConfig::getEnv("YARP_MCAST_TEST")!="");
    /*
    if (test) {
        printf("  MULTICAST is being extended; some temporary status messages added\n");
        printf("  Local: %s\n", local.toString().c_str());
        printf("  Remote: %s\n", remote.toString().c_str());
    }
    */
    proto.takeStreams(YARP_NULLPTR); // free up port from tcp

    if (sender) {
        /*
            Multicast behavior seems a bit variable.
            We assume here that if packages need to be broadcast
            to targets via different network interfaces, that
            we'll need to send independently on those two
            interfaces.  This may or may not always be the case,
            the author doesn't know, so is being cautious.
        */
        key = proto.getRoute().getFromName();
        if (test) {
            key += "/net=";
            key += local.getHost();
        }
        YARP_DEBUG(Logger::get(),
                    ConstString("multicast key: ") + key);
        addSender(key);
    }

    bool ok = true;
    if (isElect()||!sender) {
        if (test) {
            ok = stream->join(mcastAddress,sender,local);
        } else {
            ok = stream->join(mcastAddress,sender);
        }
    }

    if (!ok) {
        delete stream;
        return false;
    }
    proto.takeStreams(stream);
    return true;
#endif
}
开发者ID:apaikan,项目名称:yarp,代码行数:57,代码来源:McastCarrier.cpp

示例11: HttpTwoWayStream

bool yarp::os::impl::HttpCarrier::respondToHeader(ConnectionState& proto) {
    stream = new HttpTwoWayStream(proto.giveStreams(),
                                  input.c_str(),
                                  prefix.c_str(),
                                  prop,
                                  false);
    proto.takeStreams(stream);
    return true;
}
开发者ID:giuliavezzani,项目名称:yarp,代码行数:9,代码来源:HttpCarrier.cpp

示例12: respondToHeader

bool XmlRpcCarrier::respondToHeader(ConnectionState& proto) {
    shouldInterpretRosMessages(proto);
    sender = false;
    XmlRpcStream *stream = new XmlRpcStream(proto.giveStreams(),
                                            sender,
                                            interpretRos);
    if (stream==NULL) { return false; }
    proto.takeStreams(stream);
    return true;
}
开发者ID:JoErNanO,项目名称:yarp,代码行数:10,代码来源:XmlRpcCarrier.cpp

示例13: readYarpInt

int AbstractCarrier::readYarpInt(ConnectionState& proto) {
    char buf[8];
    Bytes header((char*)&buf[0],sizeof(buf));
    YARP_SSIZE_T len = proto.is().readFull(header);
    if ((size_t)len!=header.length()) {
        YARP_DEBUG(proto.getLog(),"data stream died");
        return -1;
    }
    return interpretYarpNumber(header);
}
开发者ID:BRKMYR,项目名称:yarp,代码行数:10,代码来源:AbstractCarrier.cpp

示例14: sendHeader

bool MjpegCarrier::sendHeader(ConnectionState& proto) {
    Name n(proto.getRoute().getCarrierName() + "://test");
    ConstString pathValue = n.getCarrierModifier("path");
    ConstString target = "GET /?action=stream\n\n";
    if (pathValue!="") {
        target = "GET /";
        target += pathValue;
    }
    target += " HTTP/1.1\n\n";
    Bytes b((char*)target.c_str(),target.length());
    proto.os().write(b);
    return true;
}
开发者ID:JoErNanO,项目名称:yarp,代码行数:13,代码来源:MjpegCarrier.cpp

示例15:

bool yarp::os::impl::LocalCarrier::expectExtraHeader(ConnectionState& proto) {
    portName = proto.getRoute().getToName();
    // switch over to some local structure to communicate
    peerMutex.wait();
    peer = manager.getSender(this);
    //printf("receiver %ld (%s) sees sender %ld (%s)\n",
    //       (long int) this, portName.c_str(),
    //       (long int) peer, peer->portName.c_str());
    proto.setRoute(proto.getRoute().addFromName(peer->portName));
    peerMutex.post();

    return true;
}
开发者ID:apaikan,项目名称:yarp,代码行数:13,代码来源:LocalCarrier.cpp


注:本文中的ConnectionState类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。