Example #1
0
std::string
CMMError::getFullMsg() const
{
   if (getUnderlyingError())
      return getMsg() + " [ " + underlying_->getFullMsg() + " ]";
   return getMsg();
}
Example #2
0
bool CUserService::sendMsgToGroup(const CString& groupNamw, const CString& msg, CString* retMsg)
{
	const CUser& u = CMFCUtil::getActiveDoc()->m_user;
	Json::Value jsonObj;

	jsonObj["name"] = Json::Value(CStringUtil::getStdString(groupNamw));
	jsonObj["msg"] = Json::Value(CStringUtil::getStdString(msg));
	string retStr;

	if (!this->sendData("/sendMsgToGroup", jsonObj, retStr))
	{
		retMsg->Format(_T("发送失败请检查网络"));
		return false;
	}
	if (this->getCode(retStr) != CODE::SUCCESS)
	{
		string t = getMsg(retStr);
		(*retMsg) = CStringUtil::getCString(t);
		return false;
	}

	CMFCUtil::getActiveDoc()->updateGroupHtml(groupNamw, u.m_userName, msg, false);
	CMFCUtil::getActiveView()->flushChat();
	return true;
}
Example #3
0
void KNNntpClient::doFetchArticle()
{
    KNRemoteArticle *target = static_cast<KNRemoteArticle *>(job->data());
    QCString cmd;

    sendSignal(TSdownloadArticle);
    errorPrefix = i18n("Article could not be retrieved.\nThe following error occurred:\n");

    progressValue = 100;
    predictedLines = target->lines()->numberOfLines() + 10;

    if(target->collection())
    {
        QString groupName = static_cast<KNGroup *>(target->collection())->groupname();
        if(currentGroup != groupName)
        {
            cmd = "GROUP ";
            cmd += groupName.utf8();
            if(!sendCommandWCheck(cmd, 211))       // 211 n f l s group selected
                return;
            currentGroup = groupName;
        }
    }

    if(target->articleNumber() != -1)
    {
        cmd.setNum(target->articleNumber());
        cmd.prepend("ARTICLE ");
    }
    else
    {
        cmd = "ARTICLE " + target->messageID()->as7BitString(false);
    }

    if(!sendCommandWCheck(cmd, 220))        // 220 n <a> article retrieved - head and body follow
    {
        int code = atoi(getCurrentLine());
        if(code == 430 || code == 423)      // 430 no such article found || 423 no such article number in this group
        {
            QString msgId = target->messageID()->as7BitString(false);
            // strip of '<' and '>'
            msgId = msgId.mid(1, msgId.length() - 2);
            job->setErrorString(errorPrefix + getCurrentLine() +
                                i18n("<br><br>The article you requested is not available on your news server."
                                     "<br>You could try to get it from <a href=\"http://groups.google.com/groups?selm=%1\">groups.google.com</a>.")
                                .arg(msgId));
        }
        return;
    }

    QStrList msg;
    if(!getMsg(msg))
        return;

    progressValue = 1000;
    sendSignal(TSprogressUpdate);

    target->setContent(&msg);
    target->parse();
}
Example #4
0
void testFielddefs(database* db)
{
    short ret = createTestDataBase(db);
    BOOST_CHECK_MESSAGE(0 == ret, "createTestDataBase stat = " << ret);
    if (ret) return;
    ret = createTestTable(db);
    BOOST_CHECK_MESSAGE(0 == ret, "createTestTable stat = " << ret);
    if (ret) return;
    try
    {
        short tableid = 1;
        table_ptr tb = openTable(db, tableid, TD_OPEN_NORMAL);
        
        //Check nullbit
        const tabledef* td = tb->tableDef();
        const fielddef* fd = &td->fieldDefs[1];
        BOOST_CHECK_MESSAGE(fd->nullbit() == 0, "Invalid nullbit = " << (int)fd->nullbit());
        BOOST_CHECK_MESSAGE(fd->nullbytes() == 2, "Invalid nullbytes = " << (int)fd->nullbytes());

        fd = &td->fieldDefs[8]; //fd8
        BOOST_CHECK_MESSAGE(fd->nullbit() == 7, "Invalid nullbit = " << (int)fd->nullbit());
        BOOST_CHECK_MESSAGE(fd->nullbytes() == 2, "Invalid nullbytes = " << (int)fd->nullbytes());
        //fielddefs copy test
        fielddefs& fds = *fielddefs::create();
        fds.addAllFields(tb->tableDef());
        fd = &fds[1];
        BOOST_CHECK_MESSAGE(fd->nullbit() == 0, "Invalid nullbit = " << (int)fd->nullbit());
        BOOST_CHECK_MESSAGE(fd->nullbytes() == 2, "Invalid nullbytes = " << (int)fd->nullbytes());

        // Append join field, nullbytes and nullbit specify only append fields.
        query q;
        q.select(_T("fd8"));
        tb->setQuery(&q);
        fds.addSelectedFields(tb.get());
        fd = &fds[(int)fds.size() -1];
        BOOST_CHECK_MESSAGE(fd->nullbit() == 0, "Invalid nullbit = " << (int)fd->nullbit());
        BOOST_CHECK_MESSAGE(fd->nullbytes() == 1, "Invalid nullbytes = " << (int)fd->nullbytes());
        
        //One more join 
        q.reset().select(_T("fd2"), _T("fd3"), _T("fd4"), _T("fd5"), _T("fd6"));
        tb->setQuery(&q);
        fds.addSelectedFields(tb.get());
        fd = &fds[(int)fds.size() -1];
        BOOST_CHECK_MESSAGE(fd->nullbit() == 4, "Invalid nullbit = " << (int)fd->nullbit());
        BOOST_CHECK_MESSAGE(fd->nullbytes() == 1, "Invalid nullbytes = " << (int)fd->nullbytes());

        //One more join 
        q.reset().select(_T("fd1"), _T("fd2"), _T("fd3"), _T("fd4"), _T("fd5"), _T("fd6"), _T("fd7"), _T("fd8"));
        tb->setQuery(&q);
        fds.addSelectedFields(tb.get());
        fd = &fds[(int)fds.size() -1];
        BOOST_CHECK_MESSAGE(fd->nullbit() == 7, "Invalid nullbit = " << (int)fd->nullbit());
        BOOST_CHECK_MESSAGE(fd->nullbytes() == 1, "Invalid nullbytes = " << (int)fd->nullbytes());
        fds.release();
    }
    catch (bzs::rtl::exception& e)
    {
        _tprintf(_T("Error ! %s\n"), (*getMsg(e)).c_str());
    }
}
Example #5
0
void testFieldValue(database* db)
{
    try
    {
        short tableid = 1;
        table_ptr tb = openTable(db, tableid, TD_OPEN_NORMAL);
        tb->clearBuffer();
        for (int i = 1; i < tb->tableDef()->fieldCount; ++i)
        {
            tb->setFVNull(i, true);
            BOOST_CHECK_MESSAGE(tb->getFVNull(i) == true, "Invalid getFVNull i = " << i);
            tb->setFVNull(i, false);
            BOOST_CHECK_MESSAGE(tb->getFVNull(i) == false, "Invalid getFVNull i = " << i);
        }

        // field 0 is not nullable
        short index = 0;
        tb->setFVNull(index, true);
        BOOST_CHECK_MESSAGE(tb->getFVNull(index) == false, "Invalid getFVNull(0) ");
        tb->setFVNull(index, false);
        BOOST_CHECK_MESSAGE(tb->getFVNull(index) == false, "Invalid getFVNull(0) ");
 
    }
    catch (bzs::rtl::exception& e)
    {
        _tprintf(_T("Error ! %s\n"), (*getMsg(e)).c_str());
    }
}
Example #6
0
void ClientSocket::BufferToMsg(Message * msg, const  char  *buffer){
	string getMsg(buffer);
	Json::Reader reader;
	Json::Value root;
	if (reader.parse(getMsg, root))  // reader将Json字符串解析到root,root将包含Json里所有子元素  
	{
		//std::stringstream strValue;


		msg->msg_type = root["msg_type"].asInt();  // 访问节点,upload_id = "UP000000"  
		msg->content = root["content"].asString();  // 访问节点,upload_id = "UP000000"  
		string timestr = root["time"].asString();  // 访问节点,upload_id = "UP000000"  
		int    a, b, c, d, e, f;
		sscanf_s(timestr.c_str(), "%d-%d-%d %d:%d:%d", &a, &b, &c, &d, &e, &f);
		CTime    time(a, b, c, d, e, f);
		msg->time = time;
		string from_id = root["FromID"].asString();
		sscanf_s(from_id.c_str(), "%ul", &(msg->FromID));
		string to_id = root["ToID"].asString();

		sscanf_s(to_id.c_str(), "%ul", &(msg->ToID));
		msg->myWPragam = root["myWPragam"].asInt();
	}
	/*
	实现
	*/
}
Example #7
0
void trayIconActivated(GObject *trayIcon, gpointer window)
{
	if(gtk_status_icon_get_blinking(GTK_STATUS_ICON (trayIcon))==FALSE){
		gtk_widget_show(GTK_WIDGET(window));
		gtk_window_deiconify(GTK_WINDOW(window));
	}
	else{
printf("-------------------[click to create window start]----------------\n");
		//if(Msghead != NULL)
		char ip[20]; 
		strcpy(ip,Msghead->ip);
printf("ip:%s\n",ip);
		char name[20]; 
		strcpy(name,Msghead->name);
printf("name:%s\n",name);
		char msg[1024];
		bzero(msg,1024);
		getMsg(ip,msg);
printf("msg:%s\n",msg);
		if(Msghead == NULL)
			gtk_status_icon_set_blinking (trayIcon,FALSE);
		
		createChatWindow(ip,name,msg);
		//showMessage(msg.message,p->textViewAll);

printf("-------------------[click to create window end ]----------------\n");
	}

}
Example #8
0
void testWriatbleRecordFieldValue(database* db)
{
    try
    {
        activeTable tb(db, _T("nulltest"));
        writableRecord& wr = tb.getWritableRecord();
        wr.clear();
        for (int i = 1; i < (int)wr.fieldDefs()->size(); ++i)
        {
            wr[i].setNull(true);
            BOOST_CHECK_MESSAGE(wr[i].isNull() == true, "Invalid isNull i = " << i);
            wr[i].setNull(false);
            BOOST_CHECK_MESSAGE(wr[i].isNull() == false, "Invalid isNull i = " << i);
        }

        // field 0 is not nullable
        short index = 0;
        wr[index].setNull(true);
        BOOST_CHECK_MESSAGE(wr[index].isNull() == false, "Invalid isNull ");
        wr[index].setNull(false);
        BOOST_CHECK_MESSAGE(wr[index].isNull() == false, "Invalid isNull ");
 
    }
    catch (bzs::rtl::exception& e)
    {
        _tprintf(_T("Error ! %s\n"), (*getMsg(e)).c_str());
    }
}
Example #9
0
qChat::qChat(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::qChat)
{
    ui->setupUi(this);

    /* server parameters */
    _host = "achat.lorenzobianconi.net";
    _port = 9999;
    _nick = getHostname() + QString("@") + QHostInfo::localHostName();
    _sock = new QTcpSocket(this);
    _connecTimer = new QTimer(this);

    _ws = CLIENT_NOT_AUTHENTICATED;

    _attempt = 1;

    tableFormat.setBorder(0);

    connect(ui->msgEdit, SIGNAL(returnPressed()), this, SLOT(sndMsg()));
    connect(_sock, SIGNAL(connected()), this, SLOT(clientAuth()));
    connect(_sock, SIGNAL(readyRead()), this, SLOT(getMsg()));
    connect(_sock, SIGNAL(error(QAbstractSocket::SocketError)),
            this, SLOT(displayError(QAbstractSocket::SocketError)));
    connect(_connecTimer, SIGNAL(timeout()), this, SLOT(try_connect()));

    _sock->connectToHost(_host, _port);
    _connecTimer->setSingleShot(true);
}
Example #10
0
bool CUserService::searchFriend(const CString& friendName, vector<CString>& friList, CString& retMsg)
{
	Json::Value sendJson;
	sendJson["name"] = Json::Value(CStringUtil::getStdString(friendName));

	string retStr;
	if (!this->sendData("/user/searchPeo", sendJson, retStr))
	{
		retMsg.Format(_T("发送失败请检查网络"));
		return false;
	}
	if (this->getCode(retStr) != CODE::SUCCESS)
	{
		string t = getMsg(retStr);
		retMsg = CStringUtil::getCString(t);
		return false;
	}

	Json::Value retJson = this->getData(retStr);
	Json::Value namesJsonArray = retJson["names"];
	for (int i = 0; i < namesJsonArray.size(); i++)
	{
		CString freNamesData(namesJsonArray[i].asCString());
		friList.push_back(freNamesData);
	}
	return true;
}
Example #11
0
/*
 * Send a customer message.
 */
void
SendCustMsg(
	const char *srcFile,	/* Caller's source file. */
	const int srcLine,	/* Caller's source line. */
	int msgNum,		/* Message catalog number. */
	...)
{
	va_list	args;
	char *fmt;
	char msg_buf[MAXLINE];
	char *msg;
	int saveErrno;

	saveErrno = errno;
	fmt = getMsg(msgNum);
	va_start(args, msgNum);
	vsnprintf(msg_buf, sizeof (msg_buf), fmt, args);
	va_end(args);
	msg = sendMsg(msgNum, msg_buf);
	if (TraceFlags != NULL) {
		_Trace(TR_cust, srcFile, srcLine, "Message %d: %s",
		    msgNum, msg);
	}
	errno = saveErrno;
}
Example #12
0
int  CMessagePushMgr::Run()
{
	while (m_bEnableRun)
	{
		// Wait for event
		boost::unique_lock<boost::mutex> lock(m_mutexCond);
		boost::system_time const timeout = boost::get_system_time() + boost::posix_time::milliseconds(1000);
		m_cond.timed_wait(lock, timeout);

		SPushMessage_ptr msg;
		while (getMsg(msg) && m_bEnableRun)
		{
			//通过苹果的APNs服务推送
			if (msg->pushway == Push_APNs)
			{
				SAPNs_Message apns_msg;
				apns_msg.userinfo = msg->custom_info;
				if (!msg->content.empty())
					apns_msg.body = msg->content;

				string msg_js = apns_msg.ToJson();
				string token = msg->devicetoken;
				string account = msg->account;

				APNs_Push_Message(token, account, msg_js);
			}
			else     //腾讯信鸽推送
			{	
				//IOS手机
				if (msg->ttype == Terminal_IOS)
				{
					SXG_Message_IOS xg_ios_msg;
					xg_ios_msg.custom = msg->custom_info;
					if (!msg->content.empty())
						xg_ios_msg.body = msg->content;
					string msg_js = xg_ios_msg.ToJson();
					string account = msg->account;

					XG_Push_Message(Terminal_IOS, account, msg_js);
				}
				else //Android手机
				{
					SXG_Message_Andriod xg_android_msg;
					xg_android_msg.custom_content = msg->custom_info;
					if (!msg->content.empty())
						xg_android_msg.content = msg->content;
					string msg_js = xg_android_msg.ToJson();
					string account = msg->account;

					XG_Push_Message(Terminal_Android, account, msg_js);

				}
				
			}
		}
	}
	m_hThreadStopEvent.notify_all();
	return 0;
}
Example #13
0
string Mailman::read()
{
	int len;
	if((len=(recv(socket_fd,message,MAXDATASIZE,0)))==-1)
	{ /*tcp_log<<"recv error\n";*/ }
	else message[len]='\0';
	return getMsg();
}
Example #14
0
Logic::Logic(QObject *parent) :
    QObject(parent)
{
    client = new Client();
    ship = new Ship();
    gals = new QVector<Gals*>();
    connect(client,SIGNAL(messageFormed(QString)),this,SLOT(getMsg(QString)));
}
Example #15
0
int sys_getMsg()
{
	struct Msg* ptr;
	if (argptr(0, (void*)&ptr, sizeof(*ptr)) < 0)
		return -1;
	getMsg(proc->pid, ptr);
	return 0;
}
Example #16
0
void loop() {
	char *msg;
	if ((msg = getMsg()) != 0) {
		procMsg(msg);
	}

	procBut();
	procClock();
}
Example #17
0
void testTableStore(database* db)
{
    try
    {
        // All null test
        short tableid = 1;
        table_ptr tb = openTable(db, tableid, TD_OPEN_NORMAL);
        tb->setKeyNum(0);
        tb->clearBuffer();
        fields& fds = tb->fields();
        
        fds[(short)0] = 1;
        for (short i = 1 ;i < (short)fds.size(); ++i)
        {
            fds[i] = _T("123");
            fds[i].setNull(true);
        }
        tb->insert();
        BOOST_CHECK_MESSAGE(tb->stat() == 0, "testStore insert stat = " << tb->stat());
        
        tb->clearBuffer();
        fds[(short)0] = 1;
        tb->seek();
        BOOST_CHECK_MESSAGE(tb->stat() == 0, "testStore seek stat = " << tb->stat());
        for (short i = 1 ;i < (short)fds.size(); ++i)
            BOOST_CHECK_MESSAGE(fds[i].isNull() == true, "testStore isNull field num = " << i);

        // All not null test
        tb->clearBuffer(table::defaultNull);
        fds[(short)0] = 2;
        for (short i = 1 ;i < (short)fds.size(); ++i)
            fds[i].setNull(false);
        tb->insert();
        BOOST_CHECK_MESSAGE(tb->stat() == 0, "testStore insert stat = " << tb->stat());

        tb->clearBuffer(table::defaultNull);
        
        fds[(short)0] = 2;
        tb->seek();
        BOOST_CHECK_MESSAGE(tb->stat() == 0, "testStore seek stat = " << tb->stat());
        for (short i = 1 ;i < (short)fds.size(); ++i)
        {
            BOOST_CHECK_MESSAGE(fds[i].isNull() == false, "testStore isNull field num = " << i);
            //Test Default value
            __int64 dv = 0;
            if (i == 5) dv = -1;
            if (i == 6) dv = -123456;
            if (i != 10) //ignore timestamp
                BOOST_CHECK_MESSAGE(fds[i].i64() == dv, "testStore defaultValue field num = " 
                    << i << " " << fds[i].i64());
        }
    }
    catch (bzs::rtl::exception& e)
    {
        _tprintf(_T("Error ! %s\n"), (*getMsg(e)).c_str());
    }
}
Example #18
0
bool MainMsg::operator != (const MainMsg& message) const
{
	if((this->Author != message.getAuthor()) || (this->Message != getMsg()))
		return true;

	else
		return false;

}
Example #19
0
bool UDPdriver::recieve(UDPmsg* msg, __time_t sec, __suseconds_t usec) {

    struct timeval		timeOut;
    struct timeval*		timeOut_param;


    //ennyit fogunk aludni, amig nem jon semmi
    timeOut.tv_sec	= sec;
    timeOut.tv_usec	= usec;


    //ha 0-k, akkor blokkolosan varunk
    if((sec == 0) && (usec == 0))
        timeOut_param = NULL;
    else
        timeOut_param = &timeOut;


    //ha van a bufferben uzenet
    if(recieveBufferCount > 0) {

        getMsg(msg);

        return true;

    }

    //ha nincs a bufferben, de jott uzenet
    else if(UDPconn::recieve(recieveBuffer, RECIEVE_BUFFER_SIZE, &recieveBufferCount, timeOut_param)) {

        recieveBufferNextIndex = 0;

        getMsg(msg);

        return true;

    }

    //ha nincs a bufferben, es nem is jott uzenet
    else
        return false;


}
Example #20
0
void testUnuseSchema(database* db)
{
    try
    {
        db->close();
        bool ret = db->open(makeUri(PROTOCOL, HOSTNAME, DBNAMEV3, _T("")), TYPE_SCHEMA_BDF,TD_OPEN_NORMAL);
        BOOST_CHECK_MESSAGE(ret == true, "db open stat = " << db->stat());
        table_ptr tb = openTable(db, _T("nulltest"), TD_OPEN_NORMAL);
        tb->setKeyNum(0);
        tb->clearBuffer();
        fields& fds = tb->fields();
        fds[(short)0] = 1;
        tb->seek();
        BOOST_CHECK_MESSAGE(tb->stat() == 0, "UnuseSchema seek stat = " << tb->stat());
        for (short i = 1 ;i < (short)fds.size(); ++i)
            BOOST_CHECK_MESSAGE(fds[i].isNull() == true, "UnuseSchema isNull field num = " << i);

        //open second table
        table_ptr tb2 = openTable(db, _T("nulltest"), TD_OPEN_NORMAL);
        BOOST_CHECK_MESSAGE(db->stat() == 0, "UnuseSchema openTable stat = " << db->stat());

        //shared tabledef
        BOOST_CHECK_MESSAGE(db->dbDef()->tableCount() == 1, "tableCount = " << db->dbDef()->tableCount());

        tb2->setKeyNum(0);
        tb2->clearBuffer(table::defaultNull);

        //default values
        fields& fds2 = tb2->fields();
        for (short i = 1 ;i < (short)fds.size(); ++i)
        {
            bool v = true;
            int dv = 0;
            if (i == 0 || i == 5 || i == 6) v = false;
            BOOST_CHECK_MESSAGE(fds2[i].isNull() == v, "defaultValue isNull field num = " << i);
            if (i == 5) dv = -1;
                    
            if (i == 6) dv = -123456;
            BOOST_CHECK_MESSAGE(fds2[i].i() == dv, "defaultValue defaultValue field num = " 
                    << i << " " << fds2[i].i());
        }
    
        fds2[(short)0] = 1;
        tb2->seek();
        BOOST_CHECK_MESSAGE(tb2->stat() == 0, "UnuseSchema seek stat = " << tb2->stat());
        for (short i = 1 ;i < (short)fds2.size(); ++i)
            BOOST_CHECK_MESSAGE(fds2[i].isNull() == true, "UnuseSchema isNull field num = " << i);
    
        db->openTable(_T("abc"));
        BOOST_CHECK_MESSAGE(db->stat() == STATUS_TABLE_NOTOPEN, "openTable stat = " << db->stat());
    }
    catch (bzs::rtl::exception& e)
    {
        _tprintf(_T("testUnuseSchema Error ! %s\n"), (*getMsg(e)).c_str());
    }
}
Example #21
0
void				Client::processPacketReception()
{
  std::vector<char>		*data = getMsg(0);
  ServerOpcodes		        opcode = getOpcode(data);

  data->erase(data->begin(), data->begin() + sizeof(ServerOpcodes));
  for (int i = 0; i < NB_OPCODES; i++)
    if (protocols[i].opcode == opcode)
      (this->*(protocols[i]).protocolFunction)(data);
  delete (data);
}
Example #22
0
void testWRStore(database* db)
{
    try
    {
        // All null test
        activeTable tb(db, _T("nulltest"));
        writableRecord& wr = tb.getWritableRecord();
        wr.clear();
        
        wr[(short)0] = 3;
        for (short i = 1 ;i < (short)wr.size(); ++i)
        {
            wr[i] = _T("123");
            wr[i].setNull(true);
        }
        wr.save();
       
        wr.clear();
        wr[(short)0] = 3;
        bool ret = wr.read();
        BOOST_CHECK_MESSAGE(ret == true, "testWRStore read ");
        for (short i = 1 ;i < (short)wr.size(); ++i)
            BOOST_CHECK_MESSAGE(wr[i].isNull() == true, "testWRStore isNull field num = " << i);

        // All not null test
        wr.clear();
        wr[(short)0] = 4;
        wr[1] = 2;
        for (short i = 1 ;i < (short)wr.size(); ++i)
            wr[i].setNull(false);
        wr.save();

        wr.clear();
        wr[(short)0] = 4;
        ret = wr.read();
        BOOST_CHECK_MESSAGE(ret == true, "testWRStore read");
        for (short i = 1 ;i < (short)wr.size(); ++i)
        {
            BOOST_CHECK_MESSAGE(wr[i].isNull() == false, "testWRStore isNull field num = " << i);
            //Test Default value
            __int64 dv = 0;
            if (i == 1) dv = 2;
            if (i == 5) dv = -1;
            if (i == 6) dv = -123456;
            if (i != 10) //ignore timestamp
                BOOST_CHECK_MESSAGE(wr[i].i64() == dv, "testWRStore defaultValue field num = " 
                    << i << " " << wr[i].i64());
        }
    }
    catch (bzs::rtl::exception& e)
    {
        _tprintf(_T("Error ! %s\n"), (*getMsg(e)).c_str());
    }
}
Example #23
0
void EReader::processMsgs(void) {
	m_pClientSocket->onSend();
	checkClient();

	ibapi::shared_ptr<EMessage> msg = getMsg();

	if (!msg.get())
		return;

	const char *pBegin = msg->begin();

	while (processMsgsDecoder_.parseAndProcessMsg(pBegin, msg->end()) > 0) {
		msg = getMsg();

		if (!msg.get())
			break;

		pBegin = msg->begin();
	} 
}
Example #24
0
void ha(int sig)
{
	int m=getMsg(time);
	int i;
	printf("sender pid: %ld msg: %d\n",getpid(),m);
		message msg;
		msg.type=par;
		msg.i=m;
		if(msgsnd(id,&msg,sizeof(long),0)==-1)perror("msgsnd");
	alarm(5);
}
Example #25
0
//发送各种UDP广播消息
void Widget::sndMsg(MsgType type, QString srvaddr)
{
    QByteArray data;
    QDataStream out(&data, QIODevice::WriteOnly);
    QString address = getIP();

    /*向要发送的数据中写入信息类型type、用户名(使用getUsr()函数获取),
     * 其中,type用于接收端区分信息类型,从而可以对不同类型的信息进行
     * 不同的处理
     */
    out << type << getUsr();

    switch(type)
    {
    case Msg:
        /* 对于普通的聊天消息Msg,首先判断发送的消息是否为空,如果为空,
         * 则进行警告;然后向发送的数据中写入本机的IP地址和用户输入的
         * 聊天信息文本
         */
        if(ui->msgTxtEdit->toPlainText() == "")
        {
            QMessageBox::warning(0, tr("警告"), tr("发送内容不能为空"),
                                 QMessageBox::Ok);
            return;
        }
        out << address << getMsg();
        ui->msgBrowser->verticalScrollBar()->setValue(
                    ui->msgBrowser->verticalScrollBar()->maximum());
        break;
    case UsrEnter:
        //对于新用户加入UsrEnter,只是简单地向数据中写入IP地址
        out << address;
        break;
    case UsrLeft:
        //对于用户离开UsrLeft,不需要进行其他操作
        break;
    case FileName:
    {
        //对于发送文件名FileName和拒绝接受文件Refuse,这里先不进行处理,稍后添加
        int row = ui->usrTblWidget->currentRow();
        QString clntaddr = ui->usrTblWidget->item(row, 1)->text();
        out << address << clntaddr << fileName;
        break;
    }
    case Refuse:
    {
        out << srvaddr;
        break;
    }
    }
    udpSocket->writeDatagram(data, data.length(), QHostAddress::Broadcast, port);
}
void SpyMini::moveIt(){
	SOCKET s= getSocket();
	char *message;
	message = getMsg();

	if (send(s, message, strlen(message), 0) < 0)
	{
		puts("Send failed");
		return;
	}
	puts("Data Send\n");

}
Example #27
0
/*
 * Error related to a system call.
 * Write a message with the errno value to the logfile.
 */
void
SysError(
	const char *srcFile,	/* Caller's source file. */
	const int srcLine,	/* Caller's source line. */
	const char *fmt,	/* printf() style format. */
	...)
{
	char msg_buf[MAXLINE];
	char *msg;
	char *p, *pe;
	int saveErrno;

	saveErrno = errno;

	/*
	 * Format message and add error number.
	 */
	p = msg_buf;
	pe = p + sizeof (msg_buf) - 1;

	/* Catalog message. */
	snprintf(p, Ptrdiff(pe, p), "%s", getMsg(14082));
	p += strlen(p);
	snprintf(p, Ptrdiff(pe, p), ": ");
	p += strlen(p);

	/* The message */
	if (fmt != NULL) {
		va_list args;

		va_start(args, fmt);
		vsnprintf(p, Ptrdiff(pe, p), fmt, args);
		va_end(args);
		p += strlen(p);
	}

	/* Error number */
	if (saveErrno != 0) {
		snprintf(p, Ptrdiff(pe, p), ": ");
		p += strlen(p);
		(void) StrFromErrno(saveErrno, p, Ptrdiff(pe, p));
		p += strlen(p);
	}
	*p = '\0';

	msg = sendMsg(14082, msg_buf);
	errno = 0;	/* Already included error number. */
	_Trace(TR_err, srcFile, srcLine, "%s", msg);
	errno = saveErrno;
}
Example #28
0
int main(void)
{
	int msgId;
	pid_t  pid;
	
	pid = fork();
	if(pid > 0)
	{
		int i;
		MsgBuf data;
		
		msgId = createMsg(KEY);
		MSG_ID = msgId;
		for(i = 0; i < 10; i++)
		{
			sleep(1);
			data.id = 1;
			sprintf(data.text, "Hello [%d]", i);
			if(msgsnd(msgId, &data, sizeof(MsgBuf), 0) < 0)
			{
				perror("msgsnd fail");	
				exit(-2);
			}
		}
		
	}else if(pid == 0)
	{
		sleep(1);
		MsgBuf data;
		
		msgId = getMsg(KEY);
		MSG_ID = msgId;
		while(1)
		{
			if(msgrcv(msgId, &data, sizeof(data), 1, 0) < 0)
			{
				perror("msgrcv fail");	
				exit(-2);
			}
			printf("data[%s] pid=%d\n", data.text, getpid());
		}
		
		exit(0);
	}else
	{
		perror("Fork Error");	
		exit(-2);
	}
}
Example #29
0
/*
 * Fatal error related to a system call.
 * Write a message with the errno value to the logfile and terminate.
 */
void
_LibFatal(
	const char *srcFile,		/* Caller's source file. */
	const int srcLine,		/* Caller's source line. */
	const char *functionName,	/* Name of failing function. */
	const char *functionArg)	/* Argument to function */
{
	char msg_buf[MAXLINE];
	char *msg;
	char *p, *pe;
	int saveErrno;

	saveErrno = errno;

	/*
	 * Format message and add error number.
	 */
	p = msg_buf;
	pe = p + sizeof (msg_buf) - 1;
	snprintf(p, Ptrdiff(pe, p), "%s", getMsg(14080));
	p += strlen(p);
	if (functionArg == NULL) {
		functionArg = "NULL";
	}
	snprintf(p, Ptrdiff(pe, p), ": %s(%s) called from: %s:%d",
	    functionName, functionArg, srcFile, srcLine);
	p += strlen(p);
	if (saveErrno != 0) {
		snprintf(p, Ptrdiff(pe, p), ": ");
		p += strlen(p);
		(void) StrFromErrno(saveErrno, p, Ptrdiff(pe, p));
		p += strlen(p);
	}
	*p = '\0';

	msg = sendMsg(14080, msg_buf);
	errno = 0;	/* Already included error number */
	_Trace(TR_err, srcFile, srcLine, "%s", msg);
#if !defined(TEST)
	if (ErrorExitStatus == EXIT_FATAL) {
		exit(EXIT_FATAL);
	}
	_exit(ErrorExitStatus);

#else /* !defined(TEST) */
	printf("*** _LibFatal() would exit(%d)\n",
	    (ErrorExitStatus != 0) ? ErrorExitStatus : EXIT_FATAL);
#endif /* !defined(TEST) */
}
Example #30
0
void main()
{
	FILE *forward = fopen("forward.bin","wb+");
	FILE *backward = fopen("backward.bin","wb+");
	while(1)
	{
	struct msg Msg;
	printf("\t\t\t\t=>:");fflush(stdin);
	gets(Msg.text);
	if(cmp(Msg.text,"exit") == 0)
		exit(0);
	putMsg(Msg,forward);
	printf("==>%s",getMsg(backward));
	}

}