Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of libMiMic by
Diff: mbed/mod/ModWebSocket.cpp
- Revision:
- 72:c118a7aa37a3
- Parent:
- 58:03b89038b21a
- Child:
- 73:8c7dd6fd462e
diff -r 855020258513 -r c118a7aa37a3 mbed/mod/ModWebSocket.cpp
--- a/mbed/mod/ModWebSocket.cpp Tue Jun 10 03:30:41 2014 +0000
+++ b/mbed/mod/ModWebSocket.cpp Fri Jun 13 11:06:33 2014 +0000
@@ -33,17 +33,16 @@
if(this->_mod==NULL){
return false;
}
+ bool ret=false;
//initialize websocket
NyLPC_cModWebSocket_initialize(this->_mod,this->_path);
if(NyLPC_cModWebSocket_canHandle(this->_mod,i_connection._ref_inst)){
- if(NyLPC_cModWebSocket_execute(this->_mod,i_connection._ref_inst)){
- return true;
- }
+ ret=NyLPC_cModWebSocket_execute(this->_mod,i_connection._ref_inst)?true:false;
}
NyLPC_cModWebSocket_finalize(this->_mod);
free(this->_mod);
this->_mod=NULL;
- return false;
+ return ret;
}
bool ModWebSocket::write(const void* i_tx_buf,int i_tx_size)
{
@@ -53,38 +52,17 @@
return NyLPC_cModWebSocket_write(this->_mod,i_tx_buf,i_tx_size)?true:false;
}
-static NyLPC_TBool fmt_handler(void* i_inst,const void* i_buf,NyLPC_TUInt32 i_len)
-{
- return NyLPC_iHttpPtrStream_write((NyLPC_TiHttpPtrStream_t*)i_inst,i_buf,i_len);
-}
+
- bool ModWebSocket::writeF(const char* i_fmt,...)
+ bool ModWebSocket::writeFormat(const char* i_fmt,...)
{
- NyLPC_TInt16 l;
+ bool ret;
va_list a;
//ストリームの状態を更新する。
- NyLPC_cModWebSocket_update(this->_mod,0);
-
- //書式文字列の長さを計算
va_start(a,i_fmt);
- l=NyLPC_cFormatWriter_length(i_fmt,a);
+ ret=NyLPC_cModWebSocket_writeFormatV(this->_mod,i_fmt,a)?true:false;
va_end(a);
- if(!NyLPC_cModWebSocket_writePayloadHeader(this->_mod,l)){
- //CLOSE
- NyLPC_OnErrorGoto(Error);
- }
- va_start(a,i_fmt);
- if(!NyLPC_cFormatWriter_print(fmt_handler,NyLPC_cHttpdConnection_refStream(this->_mod->_ref_connection),i_fmt,a)){
- va_end(a);
- NyLPC_OnErrorGoto(Error);
- }
- va_end(a);
- NyLPC_iHttpPtrStream_flush(NyLPC_cHttpdConnection_refStream(this->_mod->_ref_connection));
- return true;
- Error:
- NyLPC_cHttpdConnection_closeSocket(this->_mod->_ref_connection);
- this->_mod->_payload_st=NyLPC_TcModWebSocket_ST_CLOSED;
- return false;
+ return ret;
}
int ModWebSocket::read(void* i_rx_buf,int i_rx_size)
