Skip to content

Commit cad84d0

Browse files
committed
Added function "reset" to draft , so draft objects can be reused.
Encapsulate WebSocketClient's function releaseAndInitialize.
1 parent 26d7be7 commit cad84d0

File tree

5 files changed

+24
-6
lines changed

5 files changed

+24
-6
lines changed

src/net/tootallnate/websocket/Draft.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,8 @@ protected boolean basicAccept( Handshakedata handshakedata ){
105105

106106
public abstract List<Framedata> createFrames( String text , boolean mask );
107107

108+
public abstract void reset( );
109+
108110
public List<ByteBuffer> createHandshake( Handshakedata handshakedata , Role ownrole ){
109111
return createHandshake( handshakedata , ownrole , true );
110112
}

src/net/tootallnate/websocket/WebSocket.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,7 @@ public void abort( String problemmessage ) {
308308
*/
309309
public void close() {
310310
//TODO Send HTTP error here in some cases / create abort method
311+
draft.reset();
311312
currentframe = null;
312313
handshakerequest = null;
313314
try {

src/net/tootallnate/websocket/WebSocketClient.java

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ public void send(String text) throws IOException {
146146
* Reinitializes and prepares the class to be used for reconnect.
147147
* @return
148148
*/
149-
public void releaseAndInitialize()
149+
private void releaseAndInitialize()
150150
{
151151
conn = null;
152152
client = null;
@@ -247,13 +247,17 @@ private void finishConnect() throws IOException, InvalidHandshakeException {
247247
}
248248

249249
private void sendHandshake() throws IOException, InvalidHandshakeException {
250-
String path = uri.getPath();
251-
if (path.indexOf("/") != 0) {
252-
path = "/" + path;
253-
}
250+
String path;
251+
String part1 = uri.getPath();
252+
String part2 = uri.getQuery();
253+
if( part1 != null )
254+
path = part1;
255+
else
256+
path = "/";
257+
if( part2 != null)
258+
path += "?" + part2;
254259
int port = getPort();
255260
String host = uri.getHost() + (port != WebSocket.DEFAULT_PORT ? ":" + port : "");
256-
//String origin = "x"; // TODO: Make 'origin' configurable
257261

258262
HandshakedataImpl1 handshake = new HandshakedataImpl1();
259263
handshake.setResourceDescriptor ( path );

src/net/tootallnate/websocket/drafts/Draft_10.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,4 +331,9 @@ else if( payloadlength == 126 ){
331331

332332
return frame;
333333
}
334+
335+
@Override
336+
public void reset( ) {
337+
incompleteframe = null;
338+
}
334339
}

src/net/tootallnate/websocket/drafts/Draft_75.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,5 +143,11 @@ else if ( newestByte == END_OF_FRAME && readingState ) { // End of Frame
143143
}
144144
return frames;
145145
}
146+
147+
@Override
148+
public void reset( ) {
149+
readingState = false;
150+
this.currentFrame = null;
151+
}
146152

147153
}

0 commit comments

Comments
 (0)