Skip to content

Websocket2 - #2

Open
HendrikHuebner wants to merge 10 commits into
masterfrom
websocket
Open

Websocket2#2
HendrikHuebner wants to merge 10 commits into
masterfrom
websocket

Conversation

@HendrikHuebner

Copy link
Copy Markdown
Owner

No description provided.

Comment thread Source/NSURLSessionWebSocketTask.m Outdated
NSMutableArray *queue;
NSMutableArray *pingHandlers;
NSData *pingPayload;
GSURLSessionWebSocketMessageSendState active;

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

combine the send states

Comment thread Source/NSURLSessionWebSocketTask.m Outdated
GSURLSessionWebSocketLifecycleStateFailed = 3,
};

typedef NS_ENUM(NSUInteger, GSURLSessionWebSocketReceivePhase) {

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rename: WSReceiveContentType

Comment thread Source/NSURLSessionWebSocketTask.m Outdated
GSURLSessionWebSocketSendQueueEntryKindClose = 2,
};

typedef NS_ENUM(NSUInteger, GSURLSessionWebSocketLifecyclePhase) {

@HendrikHuebner HendrikHuebner Jul 28, 2026

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rename: WSTaskConnectionState

Comment thread Source/NSURLSessionWebSocketTask.m Outdated
@class NSMutableArray;
@class NSMutableData;

typedef NS_ENUM(NSUInteger, GSURLSessionWebSocketSendQueueEntryKind) {

@HendrikHuebner HendrikHuebner Jul 28, 2026

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rename: WSMessageSendType

Comment thread Source/NSURLSessionWebSocketTask.m Outdated
GSURLSessionWebSocketMessageSendState active;
unsigned long long nextPingIdentifier;
BOOL frameStartRetryPending;
} GSURLSessionWebSocketSendState;

@HendrikHuebner HendrikHuebner Jul 28, 2026

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rename: WSTaskSendState

Comment thread Source/NSURLSessionWebSocketTask.m Outdated
NSData *closeReason;
BOOL closeFrameSent;
BOOL closeFrameReceived;
} GSURLSessionWebSocketLifecycleState;

@HendrikHuebner HendrikHuebner Jul 28, 2026

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rename: WSConnectionClosedContext

Comment thread Source/NSURLSessionWebSocketTask.m Outdated

typedef struct
{
GSURLSessionWebSocketLifecyclePhase phase;

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

move this to the parent ( NSURLSessionWebSocketTask )

Comment thread Source/NSURLSessionWebSocketTask.m Outdated
void (^completionHandler)(NSError *error);
GSURLSessionWebSocketSendQueueEntryKind kind;
NSURLSessionWebSocketMessageType dataType;
} GSURLSessionWebSocketSendQueueEntry;

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rename: WSSendQueueEntry

Comment thread Source/NSURLSessionWebSocketTask.m Outdated
} GSURLSessionWebSocketSendQueueEntry;

static GSURLSessionWebSocketSendQueueEntry *
GSURLSessionWebSocketDataSendQueueEntryCreate(

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this throws while we're holding a mutex we're fucked. check.

Comment thread Source/NSURLSessionWebSocketTask.m Outdated
}
else
{
[NSException raise: NSInvalidArgumentException

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

make this branch an assertion, and ensure the caller prevents an invalid type. If the user has no way to supply an invalid type, we dont need to throw at all - the assertion is enough

Comment thread Source/NSURLSessionWebSocketTask.m Outdated
dispatch_async(
[[self _session] _workQueue],
^{
curl_easy_pause([self _easyHandle], CURLPAUSE_SEND_CONT);

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lets use a helper to resume send/recv so we don't have to touch curl internals everywhere.

Comment thread Source/NSURLSessionWebSocketTask.m Outdated
}
else
{
[internal->send.queue addObject: [NSValue valueWithPointer: entry]];

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

happy branch first

Comment thread Source/NSURLSessionWebSocketTask.m Outdated
}

static void
GSURLSessionWebSocketCompleteSend(

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rename: WSTaskNotifyCompletionHandler

Comment thread Source/NSURLSessionWebSocketTask.m Outdated
}

static void
GSURLSessionWebSocketCompleteOutstandingWork(

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rename: WSTaskNotifyOutstandingCompletionHandlers

Comment thread Source/NSURLSessionWebSocketTask.m Outdated
{
GSURLSessionWebSocketDestroySendEntries(sendEntries, task, error);
GSURLSessionWebSocketCompleteReceiveHandlers(receiveHandlers, task, error);
GSURLSessionWebSocketCompletePingHandlers(task, pingHandlers, error);

@HendrikHuebner HendrikHuebner Jul 28, 2026

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

all of these should be rename to match the WSTask naming and to indicate that this simply notifies the handlers instead of doing any complex completion logic

Comment thread Source/NSURLSessionWebSocketTask.m Outdated
GS_MUTEX_UNLOCK(GSIVar(task, mutex));

GSURLSessionWebSocketCompleteReceive(task, handler, nil, error);
return 0;

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why does this return anything?

Comment thread Source/NSURLSessionWebSocketTask.m Outdated
}

static void
GSURLSessionWebSocketCompleteOutstandingWork(

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In general, I think we must be careful here about synchronization: Any completion handler and delegate callback could contain a call to the same websocket task, which may cause a deadlock if we are calling the handler while holding the task's mutex. Validate this carefully. Are there any such cases? Report.

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

Successfully merging this pull request may close these issues.

1 participant