mirror of
https://github.com/ZLMediaKit/ZLMediaKit.git
synced 2026-05-31 15:01:35 +08:00
新增websocket服务器的c api接口
This commit is contained in:
@@ -254,6 +254,33 @@ API_EXPORT uint16_t API_CALL mk_tcp_session_local_port(const mk_tcp_session ctx)
|
||||
TcpSession *session = (TcpSession *)ctx;
|
||||
return session->get_local_port();
|
||||
}
|
||||
API_EXPORT void API_CALL mk_tcp_session_send(const mk_tcp_session ctx,const char *data,int len){
|
||||
assert(ctx && data);
|
||||
if(!len){
|
||||
len = strlen(data);
|
||||
}
|
||||
TcpSession *session = (TcpSession *)ctx;
|
||||
session->send(data,len);
|
||||
}
|
||||
|
||||
API_EXPORT void API_CALL mk_tcp_session_send_safe(const mk_tcp_session ctx,const char *data,int len){
|
||||
assert(ctx && data);
|
||||
if(!len){
|
||||
len = strlen(data);
|
||||
}
|
||||
try {
|
||||
weak_ptr<TcpSession> weak_session = ((TcpSession *)ctx)->shared_from_this();
|
||||
string str = string(data,len);
|
||||
((TcpSession *)ctx)->async([weak_session,str](){
|
||||
auto session_session = weak_session.lock();
|
||||
if(session_session){
|
||||
session_session->send(str);
|
||||
}
|
||||
});
|
||||
}catch (std::exception &ex){
|
||||
WarnL << "can not got the strong pionter of this mk_tcp_session:" << ex.what();
|
||||
}
|
||||
}
|
||||
|
||||
///////////////////////////////////////////HttpBody/////////////////////////////////////////////
|
||||
API_EXPORT mk_http_body API_CALL mk_http_body_from_string(const char *str,int len){
|
||||
|
||||
Reference in New Issue
Block a user