示例#1
0
void WiFiSDCoopLib::wifiLoop() {
    if(_dev_available()) {
		_checkESPAvailableData(500); // Request fond, check routes
	}

	if (_waitAfterIPDTimer < millis()) {
		// Work queue processing
		// Check if any send command is in list:
		bool freeIPDs[WiFiSDCoopLib_COOP_SD_MAX_IPDS];
		for (unsigned char tmp = 0; tmp < WiFiSDCoopLib_COOP_SD_MAX_IPDS; tmp++) {
			freeIPDs[tmp] = true;
		}
		WorkItemStruct * queueItem = WorkQueue;
		while (queueItem != NULL) {
			if (freeIPDs[queueItem->ipd]) {
				switch (queueItem->mode) {
					case 3: // close IPD
						_sendPart("AT+CIPCLOSE=");
						char cc[3];
						itocp(cc, (int) queueItem->ipd);
						_send(cc, queueItem->timeout);
						_removeWorkQueueItem(queueItem);
						_waitAfterIPDTimer = millis() + WiFiSDCoopLib_TYPE_CLOSEIPD_DELAY;
						// Prevent any sending on this timeout
						for (unsigned char tmp = 0; tmp < WiFiSDCoopLib_COOP_SD_MAX_IPDS; tmp++) {
							freeIPDs[tmp] = false;
						}
						break;

					case 2: // command
						_send(queueItem->str, queueItem->timeout);
						_removeWorkQueueItem(queueItem);
						break;

					case 1: // File
						if (_actualFileSendRegiter == NULL) { // No active file transaction now
							_startFileTransaction(queueItem);
						}
						break;

					case 0 : // String
					default:
						_sendDataByIPD(queueItem->ipd, queueItem->str, queueItem->timeout);
						_removeWorkQueueItem(queueItem);
						break;
				}
				freeIPDs[queueItem->ipd] = false;
			}
			queueItem = (WorkItemStruct *) queueItem->next;
		}
	}
	// File sending processing:
	if (_actualFileSendRegiter != NULL) {
		_fileLoop();
	}
}
示例#2
0
/* send formatted data with \r and \n translation in addition to IAC IAC */
int telnet_vprintf(telnet_t *telnet, const char *fmt, va_list va) 
{
    static const char CRLF[] = { '\r', '\n' };
    static const char CRNUL[] = { '\r', '\0' };
	char buffer[1024];
	char *output = buffer;
	int rs, i, l;

	/* format */
	rs = vsnprintf(buffer, sizeof(buffer), fmt, va);
	if (rs >= sizeof(buffer)) {
		output = (char*)malloc(rs + 1);
		if (output == 0) {
			_error(telnet, __LINE__, __func__, TELNET_ENOMEM, 0,
					"malloc() failed: %s", strerror(errno));
			return -1;
		}
		rs = vsnprintf(output, rs + 1, fmt, va);
	}

	/* send */
	for (l = i = 0; i != rs; ++i) {
		/* special characters */
		if (output[i] == (char)TELNET_IAC || output[i] == '\r' ||
				output[i] == '\n') {
			/* dump prior portion of text */
			if (i != l)
				_send(telnet, output + l, i - l);
			l = i + 1;

			/* IAC -> IAC IAC */
			if (output[i] == (char)TELNET_IAC)
				telnet_iac(telnet, TELNET_IAC);
			/* automatic translation of \r -> CRNUL */
			else if (output[i] == '\r')
				_send(telnet, CRNUL, 2);
			/* automatic translation of \n -> CRLF */
			else if (output[i] == '\n')
				_send(telnet, CRLF, 2);
		}
	}

	/* send whatever portion of output is left */
	if (i != l) {
		_send(telnet, output + l, i - l);
	}

	/* free allocated memory, if any */
	if (output != buffer) {
		free(output);
	}

	return rs;
}
示例#3
0
文件: tty.c 项目: lizhengqiang/tinix
/*======================================================================*
                           task_tty
 *======================================================================*/
PUBLIC void task_tty()
{
	TTY*	p_tty;
	MSG 	msg;

	init_keyboard();

	for (p_tty=TTY_FIRST;p_tty<TTY_END;p_tty++) {
		init_tty(p_tty);
	}

	select_console(0);

	//清屏
	clear(TTY_FIRST);

	//欢迎信息
	printf("X-Tinix.\n");
	printf("X-Tinix: TTY(TASK) loaded.\n");
	
	//就绪消息
	_send(PID_SERVICE_PROC ,MSG_TYPE_TTY_READY);
	_recv(MSG_TYPE_PROC_READY);
	_send(PID_SERVICE_SHELL,MSG_TYPE_TTY_READY);

	//监听消息
	while (1) {

		if(recv(ANY_MSG_SRC,&msg)!=-1){
			SHELL_MSG shell_msg;
			memcpy(&shell_msg,msg.msg,sizeof(SHELL_MSG));
			switch(msg.type){
				case MSG_TYPE_SHELL:
					tty_write(TTY_FIRST+shell_msg.tty,shell_msg.command,strlen(shell_msg.command));
					break;
				case MSG_TYPE_TTY_CLEAR:
					p_tty = TTY_FIRST + shell_msg.tty;
					clear(p_tty);
					break;
				default:
					break;
			}
		}
		for (p_tty=TTY_FIRST;p_tty<TTY_END;p_tty++) {
			tty_do_read(p_tty);
			//tty_do_write(p_tty);
		}
		//clean work
		memset(&msg,0x0,sizeof(MSG));
	}
}
    void WireProtocolWriter::write(
        const StringData& ns,
        const std::vector<WriteOperation*>& write_operations,
        bool ordered,
        const WriteConcern* wc,
        std::vector<BSONObj>* results
    ) {
        bool inRequest = false;
        int opsInRequest = 0;
        Operations requestType;

        BufBuilder builder;

        std::vector<WriteOperation*>::const_iterator iter = write_operations.begin();

        while (iter != write_operations.end()) {
            // We don't have a pending request yet
            if (!inRequest) {
                (*iter)->startRequest(ns.toString(), ordered, &builder);
                inRequest = true;
                requestType = (*iter)->operationType();
            }

            // now we have a pending request, can we add to it?
            if (requestType == (*iter)->operationType() &&
                opsInRequest < _client->getMaxWriteBatchSize()) {

                // We can add to the request, lets see if it will fit and we can batch
                if(_fits(&builder, *iter)) {
                    (*iter)->appendSelfToRequest(&builder);
                    ++opsInRequest;
                    ++iter;

                    if (_batchableRequest(requestType))
                        continue;
                }
            }

            // Send the current request to the server, record the response, start a new request
            results->push_back(_send(requestType, builder, wc, ns));
            inRequest = false;
            opsInRequest = 0;
            builder.reset();
        }

        // Last batch
        if (opsInRequest != 0)
            results->push_back(_send(requestType, builder, wc, ns));
    }
void move_user(User user) {
    char buffer[MAXBUF+1];
    int choice = 0;
    int well = 0;
    do {
        if (well == 1) {
            _send(user->fd, "\n## MUOVI ## \n 1. Nord \n 2. Sud \n 3. Est \n 4. Ovest \n 5. Esci \n > Operazione effettuata. \n > ");
        } else {
            _send(user->fd, "\n## MUOVI ## \n 1. Nord \n 2. Sud \n 3. Est \n 4. Ovest \n 5. Esci \n > ");
        }
        _recv(user->fd, buffer, 0);
        while (atoi(buffer) <= 0 or atoi(buffer) > 6) {
            _send(user->fd, " > ");
            _recv(user->fd, buffer, 1);
        }
        choice = atoi(buffer);
        switch (choice) {
            case 1:
            {
                remap_user(user, user->x, user->y+4);
                well = 1;
            }
                break;
            case 2:
            {
                remap_user(user, user->x, user->y-4);
                well = 1;
            }
                break;
            case 3:
            {
                remap_user(user, user->x+4, user->y);
                well = 1;
            }
                break;
            case 4:
            {
                remap_user(user, user->x-4, user->y);
                well = 1;
            }
                break;
            default: {
                well = 0;
            }
                break;
        }
    } while (choice > 0 && choice < 5);
    
}
示例#6
0
static void _event_handler(telnet_t *telnet, telnet_event_t *ev,
		void *user_data) {
	struct user_t *user = (struct user_t*)user_data;

	switch (ev->type) {
	/* data received */
	case TELNET_EV_DATA:
		_input(user, ev->data.buffer, ev->data.size);
		break;
	/* data must be sent */
	case TELNET_EV_SEND:
		_send(user->sock, ev->data.buffer, ev->data.size);
		break;
	/* enable compress2 if accepted by client */
	case TELNET_EV_DO:
		if (ev->neg.telopt == TELNET_TELOPT_COMPRESS2)
			telnet_begin_compress2(telnet);
		break;
	/* error */
	case TELNET_EV_ERROR:
		close(user->sock);
		user->sock = -1;
		if (user->name != 0) {
			_message(user->name, "** HAS HAD AN ERROR **");
			free(user->name);
			user->name = 0;
		}
		telnet_free(user->telnet);
		break;
	default:
		/* ignore */
		break;
	}
}
示例#7
0
void fbGaze::send(int code, const char* description)
{	
	std::stringstream text;
	text << "agent " << m_agent_aID << " gaze " << m_gaze_ID << " " << description;

	_send(m_agent_aID, m_gaze_ID, code, text.str().c_str());
}
示例#8
0
bool Socket::send( const MessageHeader& messageHeader,
                   const QByteArray& message )
{
    // Send header
    if ( !_send( messageHeader ))
        return false;

    if( message.isEmpty( ))
        return true;

    // Send message data
    const char* data = message.constData();
    const int size = message.size();

    int sent = _socket->write( data, size );

    while( sent < size && isConnected( ))
        sent += _socket->write( data + sent, size - sent );

    // Needed in the absence of event loop, otherwise the reception is frozen.
    while( _socket->bytesToWrite() > 0 && isConnected( ))
        _socket->waitForBytesWritten();

    return sent == size;
}
bool XMPPAccountHandler::send(const Packet* pPacket)
{
	UT_return_val_if_fail(pPacket, false);
	
	const std::string resource = getProperty("resource");

	// make to-be-send-stream once
	std::string data;
	_createPacketStream(data, pPacket);
	
	// XMPP doesn't like binary strings, base64 encode them
	guint8* base64data = gsf_base64_encode_simple(reinterpret_cast<guint8*>(&data[0]), data.size());
	UT_return_val_if_fail(base64data, false);
	
	for (std::vector<BuddyPtr>::iterator it = getBuddies().begin(); it != getBuddies().end(); it++)
	{
		XMPPBuddyPtr pBuddy = boost::static_pointer_cast<XMPPBuddy>(*it);
		UT_continue_if_fail(pBuddy);
		if (!_send(reinterpret_cast<char*>(base64data), pBuddy))
		{
			UT_DEBUGMSG(("Error while sending message to '%s'\n", pBuddy->getAddress().c_str()));
		}
	}
	g_free(base64data);
	
	return true;
}
示例#10
0
文件: ping.c 项目: OoOverflow/tapip
static void send_packet(void)
{
	if (!buf)
		buf = xmalloc(size + ICMP_HRD_SZ);
	struct icmp *icmphdr = (struct icmp *)buf;
	static int first = 1;
	if (first) {
		printf("PING "IPFMT" %d(%d) bytes of data\n",
			ipfmt(ipaddr),
			size,
			size + ICMP_HRD_SZ + IP_HRD_SZ);
		first = 0;
	}

	/* fill icmp data */
	memset(icmphdr->icmp_data, 'x', size);
	icmphdr->icmp_type = ICMP_T_ECHOREQ;
	icmphdr->icmp_code = 0;
	icmphdr->icmp_id = _htons(id);
	icmphdr->icmp_seq = _htons(seq);
	icmphdr->icmp_cksum = 0;
	icmphdr->icmp_cksum = icmp_chksum((unsigned short *)icmphdr,
			ICMP_HRD_SZ + size);
	seq++;
	/* socket apis */
	_send(sock, buf, ICMP_HRD_SZ + size, &skaddr);
	psend++;
}
示例#11
0
static int
smb_send_raw(struct socket *socket, unsigned char *source, int length)
{
	int result;
	int already_sent = 0;

	while (already_sent < length)
	{
		result = _send(socket,
			       (void *) (source + already_sent),
			       length - already_sent);

		if (result == 0)
		{
			return -EIO;
		}
		if (result < 0)
		{
			DEBUG1("sendto error = %d\n", -result);
			return result;
		}
		already_sent += result;
	}
	return already_sent;
}
示例#12
0
void RPCClient::request(JsonBox::Value& json, char* method, JsonBox::Object params)
{
	string result = "";
	stringstream sstream("");
	
	DeviceInfo *dev = ((AppDelegate*)cocos2d::CCApplication::sharedApplication())->getDeviceInfo();
	JsonBox::Object device;
	dev->getJSONString(device);
	
	params["authkey"] = JsonBox::Value(dev->getAuthKey());
	params["device"] = JsonBox::Value(device);
	
	JsonBox::Object data;
	data["jsonrpc"] = JsonBox::Value("2.0");
	data["id"] = JsonBox::Value("1");
	data["method"] = JsonBox::Value(method);
	data["params"] = JsonBox::Value(params);

	sstream << data;

	if(_send(sstream.str()))
		_recv(result);
	
	sstream.flush();

	json.loadFromString(result);
}
示例#13
0
END_TEST

START_TEST(test_http_replace_poller)
{
	guint i;
	struct httpc *hc = _httpc_new();

	for (i = 0; i < 10; i++) {
		_send(hc, "/qio/ping:0=null");
	}

	_send(hc, "/qio/ping:1=null");
	_next(hc, "/qio/callback/1:0={\"code\":200,\"data\":null}");

	_httpc_free(hc);
}
示例#14
0
void DataOStream::disable( const Packet& packet )
{
    if( !_disable( ))
        return;
    _send( packet );
    _connections.clear();
}
示例#15
0
void ServerWorker::_processMessages()
{
    const qint64 headerSize( MessageHeader::serializedSize );

    if( _tcpSocket->bytesAvailable() >= headerSize )
        _receiveMessage();

    // Send all events
    foreach( const Event& evt, _events )
        _send( evt );
    _events.clear();

    _tcpSocket->flush();

    // Finish reading messages from the socket if connection closed
    if( _tcpSocket->state() != QAbstractSocket::ConnectedState )
    {
        while( _tcpSocket->bytesAvailable() >= headerSize )
            _receiveMessage();

        emit( connectionClosed( ));
    }
    else if( _tcpSocket->bytesAvailable() >= headerSize )
        emit _dataAvailable();
}
示例#16
0
int
rain_responce(rain_ctx_t *ctx,routine_t dest, rain_msg_t msg,int bcopy,session_t se)
{
	if(!ctx || se == RAIN_INVALID_SESSION){
		return RAIN_ERROR;
	}
	if(_is_active_id(dest) == RAIN_ERROR){
		return RAIN_ERROR;
	}
	void *tmp_data;
	if((bcopy == RAIN_COPY) && msg.sz){
		tmp_data = malloc(msg.sz);
		if(!tmp_data){
			return RAIN_ERROR;
		}
		memcpy(tmp_data,msg.data,msg.sz);
	}else{
		tmp_data = msg.data;
	}
	rain_ctxmsg_t rmsg;
	rmsg.u_data.msg = tmp_data;
	rmsg.u_sz.sz = msg.sz;
	rmsg.type = msg.type|RAIN_MSG_RSP;
	rmsg.src = rain_ctx_getid(ctx);
	rmsg.session = se;
	return _send(dest,rmsg);
}
示例#17
0
/* send TERMINAL-TYPE IS command */
void telnet_ttype_is(telnet_t *telnet, const char* ttype) {
	static const unsigned char IS[] = { TELNET_IAC, TELNET_SB,
			TELNET_TELOPT_TTYPE, TELNET_TTYPE_IS };
	_sendu(telnet, IS, sizeof(IS));
	_send(telnet, ttype, strlen(ttype));
	telnet_finish_sb(telnet);
}
static GError *
_send_and_read_reply (int fd, struct iovec *iov, unsigned int iovcount)
{
	if (!_send(fd, iov, iovcount))
		return NEWERROR(CODE_NETWORK_ERROR,
				"send error: (%d) %s",
				errno, strerror(errno));

	GError *err = NULL;
	guint8 buf[256];
	int r = sock_to_read (fd, 1000, buf, sizeof(buf)-1, &err);
	if (r < 0)
		return NEWERROR(CODE_NETWORK_ERROR,
				"read error: (%d) %s", err->code, err->message);
	if (r == 0)
		return NEWERROR(CODE_NETWORK_ERROR,
				"read error: closed by peer: (%d) %s",
				errno, strerror(errno));

	buf[r+1] = 0;

	if (!_is_success((gchar*) buf))
		return NEWERROR(CODE_BAD_REQUEST, "reply error: unexpected");
	return NULL;
}
示例#19
0
void GameClient::request(string& result, const char key[9], char type, string data)
{
	result = "";
	string authkey = ((AppDelegate*)cocos2d::CCApplication::sharedApplication())->getDeviceInfo()->getAuthKey();
	
	int length = 9+authkey.length()+data.length();
	char* packet = new char[length];
	
	for(int i=0; i<8; i++)
		packet[i] = key[i];
	packet[8] = type;
	
	const char* pAuth = authkey.c_str();
	for(int i=0; i<authkey.length(); i++)
		packet[9+i] = pAuth[i];
	
	const char* pData = data.c_str();
	for(int i=0; i<data.length(); i++)
		packet[73+i] = pData[i];
	
	if(_send(packet, length))
		_recv(result);
		
	delete[] packet;
}
示例#20
0
文件: tcp.c 项目: Auto-Droid/FreeRDP
static int transport_bio_simple_write(BIO* bio, const char* buf, int size)
{
	int error;
	int status = 0;

	if (!buf)
		return 0;

	BIO_clear_flags(bio, BIO_FLAGS_WRITE);

	status = _send((SOCKET) bio->num, buf, size, 0);

	if (status <= 0)
	{
		error = WSAGetLastError();

		if ((error == WSAEWOULDBLOCK) || (error == WSAEINTR) ||
			(error == WSAEINPROGRESS) || (error == WSAEALREADY))
		{
			BIO_set_flags(bio, (BIO_FLAGS_WRITE | BIO_FLAGS_SHOULD_RETRY));
		}
		else
		{
			BIO_clear_flags(bio, BIO_FLAGS_SHOULD_RETRY);
		}
	}

	return status;
}
示例#21
0
void fbAnimation::send(int code, const char* description)
{	
	std::stringstream text;
	text << "agent " << m_agent_aID << " animation " << m_animation_ID << " " << description;

	_send(m_agent_aID, m_animation_ID, code, text.str().c_str());
}
示例#22
0
文件: plot.c 项目: rhdunn/sptk
static void _line(void)
{
   while (_getcord(&pb))
      _send(&pb);

   _flush();
}
示例#23
0
    // sends all data or throws an exception
    void Socket::send( const char * data , int len, const char *context ) {
        while( len > 0 ) {
            int ret = -1;
            if (MONGO_FAIL_POINT(throwSockExcep)) {
#if defined(_WIN32)
                WSASetLastError(WSAENETUNREACH);
#else
                errno = ENETUNREACH;
#endif
            }
            else {
                ret = _send(data, len);
            }

            if (ret == -1)
                _handleSendError(ret, context);

            _bytesOut += ret;

            fassert(16507, ret <= len);
            len -= ret;
            data += ret;

        }
    }
示例#24
0
文件: reply.c 项目: sclaxton/chirc
void send_RPL_CREATED(cli *client){
    serv *server = client->server;
    bstring created = server->created;
    char messageBuff[513];
    sprintf(messageBuff, ":This server was created %s", charBuffromBstr(created));
    _send(client, RPL_CREATED, messageBuff);
}
ssize_t send(int sockfd, const void *buf, size_t len, int flags)
{

_send = ( ssize_t (*) (int sockfd, const void *buf, size_t len, int flags)) dlsym(RTLD_NEXT, "send");
char *errormsg;
errormsg = dlerror();
	if (errormsg != NULL)
	{
		PRINT_DEBUG("\n failed to load the original symbol %s", errormsg);
	}



	PRINT_DEBUG ("sockfd got into sendto = %d",sockfd);


	if (checkFinsHistory(getpid(),sockfd) != 0)
	{
		return ( fins_send(sockfd,buf,len,flags) );

	}
	else

	{

		PRINT_DEBUG("The original sendto should not be called ,something is WRONG!!!");
		return ( _send(sockfd,buf,len,flags)  );
	}

} // end of send
示例#26
0
int modAOS_B_PDU_Add::svc() {
	svcStart_();

	if ( ! _bpduLength) {
		if ( getMTU() > 0 ) {
			_bpduLength = getMTU();
			_mtuIsManual = true;
		}
		else if (links_[PrimaryOutputLink] ) {
			MOD_INFO("B_PDU length is unset, asking output target %s for MRU.", links_[PrimaryOutputLink]->getTarget()->getName().c_str());
			_bpduLength = links_[PrimaryOutputLink]->getTarget()->getMRU();
			_mtuIsManual = false;
		}
	}

	if (_bpduLength > 0) {
		rebuildIdleUnitTemplate_();

		while ( continueService() ) {
			std::pair<NetworkData*, int> queueTop = getData_();

			// Check every 11th unit for a new MTU
			if ( ! _mtuIsManual && getReceivedUnitCount() % 11 == 0 && links_[PrimaryOutputLink] ) {
				_bpduLength = links_[PrimaryOutputLink]->getTarget()->getMRU();
			}

			if ( msg_queue()->deactivated() ) break;

			if ( queueTop.second < 0 ) {
				MOD_ERROR("getData_() call failed.");
				continue;
			}
			else if ( ! queueTop.first ) {
				MOD_ERROR("getData_() returned with null data.");
				continue;
			}

			MOD_DEBUG("Received %d bytes to convert into AOS B_PDUs.", queueTop.first->getUnitLength());

			AOS_Bitstream_PDU* bpdu_list = _process_data(queueTop.first);
			// Deletion of received data is performed in _process_data.

			if ( ! getSendImmediately() ) {
				while (bpdu_list) {
					AOS_Bitstream_PDU* cur = bpdu_list;
					_send(cur);

					bpdu_list = (AOS_Bitstream_PDU*) bpdu_list->getNextPart();
				}
			}
			MOD_DEBUG("Finished processing incoming packets.");
		}
	}
	else {
		MOD_ERROR("No MTU obtainable, exiting service loop (pausing).");
	}

	return svcEnd_();
}
示例#27
0
void RpcServer(const SOCKET sock, const DWORD RpcAssocGroup)
{
	RPC_HEADER  _Header;

	RandomNumberInit();

	while (_recv(sock, &_Header, sizeof(_Header)))
	{
		unsigned int  _st, request_len, response_len, _a;
		BYTE  *_Request /* =  NULL */; //uncomment to avoid false warnings when compiling with -Og

		#if defined(_PEDANTIC) && !defined(NO_LOG)
		CheckRpcHeader(&_Header, _Header.PacketType, &logger);
		#endif // defined(_PEDANTIC) && !defined(NO_LOG)

		switch (_Header.PacketType)
		{
			case RPC_PT_BIND_REQ: _a = 0; break;
			case RPC_PT_REQUEST:  _a = 1; break;
			default: return;
		}

		if ( (_st = ( (signed)( request_len = LE16(_Header.FragLength) - sizeof(_Header) )) > 0
					&& (_Request = (BYTE*)malloc(request_len) )))
		{
			BYTE *_Response /* = NULL */; //uncomment to avoid warnings when compiling with -Og

			if ((_st = (_recv(sock, _Request, request_len))
						&& ( response_len = _Actions[_a].GetResponseSize(_Request, request_len) )
						&& (_Response = (BYTE*)malloc( response_len += sizeof(_Header) ))))
			{
				if ( (_st = _Actions[_a].GetResponse(_Request, _Response + sizeof(_Header), RpcAssocGroup, sock, request_len)) )
				{
					RPC_HEADER *rh = (RPC_HEADER *)_Response;

					if (_Actions[_a].ResponsePacketType == RPC_PT_RESPONSE)
						response_len = LE32(((RPC_RESPONSE*)(_Response + sizeof(_Header)))->AllocHint) + 24;

					/* *((WORD*)rh)           = *((WORD*)&_Header);
					rh->PacketFlags        = RPC_PF_FIRST | RPC_PF_LAST;
					rh->DataRepresentation = _Header.DataRepresentation;
					rh->AuthLength         = _Header.AuthLength;
					rh->CallId             = _Header.CallId;*/
					memcpy(rh, &_Header, sizeof(RPC_HEADER));
					rh->PacketType = _Actions[_a].ResponsePacketType;
					rh->FragLength = LE16(response_len);

					_st = _send(sock, _Response, response_len);

					if (DisconnectImmediately && rh->PacketType == RPC_PT_RESPONSE)
						shutdown(sock, VLMCSD_SHUT_RDWR);
				}
				free(_Response);
			}
			free(_Request);
		}
		if (!_st) return;
	}
}
示例#28
0
文件: tcp.hpp 项目: cybozu/yrmcds
 // Atomically send data.
 // @p     Data to be sent.
 // @len   Length of data starting from `p`.
 // @flush If `true`, the kernel send buffer will be flushed.
 //
 // This function sends a chunk of data atomically.  The reactor
 // thread should not call this, or it may be blocked forever.
 //
 // @return `true` if this socket is valid, `false` otherwise.
 bool send(const char* p, std::size_t len, bool flush=false) {
     lock_guard g(m_lock);
     if( ! _send(p, len, g) )
         return false;
     if( flush && empty() )
         _flush();
     return true;
 }
示例#29
0
文件: SMTP.c 项目: GaiaMagic/monit
void SMTP_helo(T S, const char *name) {
    ASSERT(S);
    S->name = name;
    _send(S, "EHLO %s\r\n", name);
    TRY
    {
        _receive(S, 250, _parseFlags);
    }
    ELSE
    {
        // If EHLO failed, fallback to HELO, but if it fails too, let the exception bubble up
        _send(S, "HELO %s\r\n", name);
        _receive(S, 250, NULL);
    }
    END_TRY;
    S->state = SMTP_Helo;
}
示例#30
0
int32_t  Process(socket_t s)
{
	_recv(s);
	_send(s);
	int32_t read_active = s->readable && !LINK_LIST_IS_EMPTY(s->pending_recv);
	int32_t write_active = s->writeable && !LINK_LIST_IS_EMPTY(s->pending_send);
	return (read_active || write_active) && s->isactived == 0;
}