Bug 159024 - [Soup] Clean up SocketStreamHandle soup implementation
Summary: [Soup] Clean up SocketStreamHandle soup implementation
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: Platform (show other bugs)
Version: WebKit Local Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Nobody
URL:
Keywords: Soup
Depends on:
Blocks:
 
Reported: 2016-06-22 09:46 PDT by Carlos Garcia Campos
Modified: 2016-06-23 00:23 PDT (History)
3 users (show)

See Also:


Attachments
Patch (16.97 KB, patch)
2016-06-22 09:52 PDT, Carlos Garcia Campos
zan: review+
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Carlos Garcia Campos 2016-06-22 09:46:00 PDT
While debugging bug #158613 today, I realized that we could clean up and simplify the SocketStreamHandle soup implementation.
Comment 1 Carlos Garcia Campos 2016-06-22 09:52:21 PDT
Created attachment 281842 [details]
Patch
Comment 2 Zan Dobersek 2016-06-22 23:19:55 PDT
Comment on attachment 281842 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=281842&action=review

> Source/WebCore/platform/network/soup/SocketStreamHandleSoup.cpp:223
> +    g_source_set_callback(m_writeReadySource.get(), reinterpret_cast<GSourceFunc>(writeReadyCallback), this, [](gpointer handle) {
> +        static_cast<SocketStreamHandle*>(handle)->deref();
> +    });

IMO the lambda would be more readable if its header was also placed on its own line, and all three lines being indented by 4 spaces compared to the start of this expression.

The rest of this patch adopts the leaked pointer into a RefPtr<> wrapper, this should do the same.
Comment 3 Carlos Garcia Campos 2016-06-22 23:34:55 PDT
(In reply to comment #2)
> Comment on attachment 281842 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=281842&action=review

Thanks for the review!

> > Source/WebCore/platform/network/soup/SocketStreamHandleSoup.cpp:223
> > +    g_source_set_callback(m_writeReadySource.get(), reinterpret_cast<GSourceFunc>(writeReadyCallback), this, [](gpointer handle) {
> > +        static_cast<SocketStreamHandle*>(handle)->deref();
> > +    });
> 
> IMO the lambda would be more readable if its header was also placed on its
> own line, and all three lines being indented by 4 spaces compared to the
> start of this expression.

I agree, I'll do that.

> The rest of this patch adopts the leaked pointer into a RefPtr<> wrapper,
> this should do the same.

Because in the other cases the callback is always called, even if the operation is cancelled, but in this case, if the source is destroyed before being dispatched the callback is not called and the handler leaked, that's why I'm using the destroy notify that is always called. Also note that the callback is called multiple times, because by default the source continues until it's cancelled or destroyed.
Comment 4 Carlos Garcia Campos 2016-06-23 00:19:53 PDT
(In reply to comment #3)
> (In reply to comment #2)
> > Comment on attachment 281842 [details]
> > Patch
> > 
> > View in context:
> > https://bugs.webkit.org/attachment.cgi?id=281842&action=review
> 
> Thanks for the review!
> 
> > > Source/WebCore/platform/network/soup/SocketStreamHandleSoup.cpp:223
> > > +    g_source_set_callback(m_writeReadySource.get(), reinterpret_cast<GSourceFunc>(writeReadyCallback), this, [](gpointer handle) {
> > > +        static_cast<SocketStreamHandle*>(handle)->deref();
> > > +    });
> > 
> > IMO the lambda would be more readable if its header was also placed on its
> > own line, and all three lines being indented by 4 spaces compared to the
> > start of this expression.
> 
> I agree, I'll do that.
> 
> > The rest of this patch adopts the leaked pointer into a RefPtr<> wrapper,
> > this should do the same.
> 
> Because in the other cases the callback is always called, even if the
> operation is cancelled, but in this case, if the source is destroyed before
> being dispatched the callback is not called and the handler leaked, that's
> why I'm using the destroy notify that is always called. Also note that the
> callback is called multiple times, because by default the source continues
> until it's cancelled or destroyed.

Sorry, I misunderstood, I thought you meant to adopt the ref in the source callback, not in the destroy notify callback. In this case I used explicit ref/deref because it's clearer than having a function that only adopts a ref and returns
Comment 5 Carlos Garcia Campos 2016-06-23 00:23:42 PDT
Committed r202370: <http://trac.webkit.org/changeset/202370>