Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Socket issue #39

Closed
cmzx3444 opened this issue Feb 9, 2014 · 4 comments
Closed

Socket issue #39

cmzx3444 opened this issue Feb 9, 2014 · 4 comments

Comments

@cmzx3444
Copy link

cmzx3444 commented Feb 9, 2014

Hi stubma,I have some problem in the CCTCPSocket sendData and init.

I found that the socket is in nonblocking mode,so send or recieve can in main thread.
And in sendData method,it just copy the data to the socket m_outBuf, the flush() method called only if the m_outBuf is not enough,.Dose is not in-time?
and in sendData() method :

if(m_outBufLen + size > kCCSocketOutputBufferDefaultSize) {
    flush();
    if(m_outBufLen + size > kCCSocketOutputBufferDefaultSize) {
        destroy();
        return false;
    }
}

if flush() dose not send anything,it may occur EINPROGRESS or EAGAIN,so it will execute:

if(m_outBufLen + size > kCCSocketOutputBufferDefaultSize) {
destroy();
return false;
}

and the socket would destroyed,but EINPROGRESS or EAGAIN is not a really socket error,we should send data when the socket buf writable.

Another issue is CCTCPSocket init method,
When socket created,it will connect to the server,it will blocking in select for blockSec.when create socket in main thread,it will blocking main thread,why not set the blockSec to zero,and check the connect event in Scheduler?

@stubma
Copy link
Owner

stubma commented Feb 9, 2014

if you need send data immediately, call flush after sendData, or call CCTCPSocketHub::sendPacket, it will flush.

@stubma
Copy link
Owner

stubma commented Feb 9, 2014

about another issue, maybe you are right, the socket code is very new and I may rafactor them a bit

@cmzx3444
Copy link
Author

cmzx3444 commented Feb 9, 2014

I think there is something wrong in

if(m_outBufLen + size > kCCSocketOutputBufferDefaultSize) {
flush();
if(m_outBufLen + size > kCCSocketOutputBufferDefaultSize) {
destroy();
return false;
}
}

if flush() dose not send anything,it may occur EINPROGRESS or EAGAIN, and the socket would destroyed. I have an idea that use a list instead of m_outBufLen ,and the element of list is a single buf,when flush() dose not send anything or send part of buf,it can be sent next time.your opinion?Thanks!

@stubma
Copy link
Owner

stubma commented Feb 9, 2014

your solution is allocating more memory to hold data, so why not directly enlarge out buffer? Or, just change kCCSocketOutputBufferDefaultSize to a bigger number.

However, I don't know when can a flush() fail, maybe in a terrible situation. Something must be wrong if a flush can fail. So I don't think destroy is a overreaction for flush failure.

@stubma stubma closed this as completed in 8026b50 Feb 9, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants