Skip to content

Commit

Permalink
Merge b32dd11 into 6098762
Browse files Browse the repository at this point in the history
  • Loading branch information
fbacchella committed Feb 16, 2019
2 parents 6098762 + b32dd11 commit b04923b
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 17 deletions.
2 changes: 1 addition & 1 deletion src/main/java/org/zeromq/ZMQ.java
Original file line number Diff line number Diff line change
Expand Up @@ -553,7 +553,7 @@ protected Context(int ioThreads)
*/
public boolean isTerminated()
{
return !ctx.checkTag();
return !ctx.isActive();
}

/**
Expand Down
26 changes: 18 additions & 8 deletions src/main/java/zmq/Ctx.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ private enum Side
}

// Used to check whether the object is a context.
private int tag;
private boolean active;

// Sockets belonging to this context. We need the list so that
// we can notify the sockets when zmq_term() is called. The sockets
Expand Down Expand Up @@ -146,7 +146,7 @@ private enum Side

public Ctx()
{
tag = 0xabadcafe;
active = true;
terminating = false;
reaper = null;
slotCount = 0;
Expand Down Expand Up @@ -202,15 +202,25 @@ private void destroy() throws IOException
// corresponding io_thread/socket objects.
termMailbox.close();

tag = 0xdeadbeef;
active = false;
}

// Returns false if object is not a context.
//
// This will also return false if terminate() has been called.
/**
* @return false if {@link #terminate()}terminate() has been called.
*/
public boolean isActive()
{
return active;
}

/**
* @return false if {@link #terminate()}terminate() has been called.
* @deprecated use {@link #isActive()} instead
*/
@Deprecated
public boolean checkTag()
{
return tag == 0xabadcafe;
return active;
}

// This function is called when user invokes zmq_term. If there are
Expand Down Expand Up @@ -711,7 +721,7 @@ private void connectInprocSockets(SocketBase bindSocket, Options bindOptions, Pe
// in waiting_for_delimiter state, which means no more writes can be done
// and the identity write fails and causes an assert. Check if the socket
// is open before sending.
if (pendingConnection.endpoint.options.recvIdentity && pendingConnection.endpoint.socket.checkTag()) {
if (pendingConnection.endpoint.options.recvIdentity && pendingConnection.endpoint.socket.isActive()) {
Msg id = new Msg(bindOptions.identitySize);
id.put(bindOptions.identity, 0, bindOptions.identitySize);
id.setFlags(Msg.IDENTITY);
Expand Down
14 changes: 8 additions & 6 deletions src/main/java/zmq/SocketBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public String toString()
private final MultiMap<String, Pipe> inprocs;

// Used to check whether the object is a socket.
private int tag;
private boolean active;

// If true, associated context was already terminated.
private boolean ctxTerminated;
Expand Down Expand Up @@ -99,7 +99,7 @@ public String toString()
protected SocketBase(Ctx parent, int tid, int sid)
{
super(parent, tid);
tag = 0xbaddecaf;
active = true;
ctxTerminated = false;
destroyed = false;
lastTsc = 0;
Expand All @@ -125,10 +125,12 @@ protected SocketBase(Ctx parent, int tid, int sid)

protected abstract void xpipeTerminated(Pipe pipe);

// Returns false if object is not a socket.
final boolean checkTag()
/**
* @return false if object is not a socket.
*/
boolean isActive()
{
return tag == 0xbaddecaf;
return active;
}

@Override
Expand Down Expand Up @@ -861,7 +863,7 @@ public final Msg recv(int flags)
public final void close()
{
// Mark the socket as dead
tag = 0xdeadbeef;
active = false;

// Transfer the ownership of the socket from this application thread
// to the reaper thread which will take care of the rest of shutdown
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/zmq/ZMQ.java
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ public static Ctx createContext()

private static void checkContext(Ctx ctx)
{
if (ctx == null || !ctx.checkTag()) {
if (ctx == null || !ctx.isActive()) {
throw new IllegalStateException();
}
}
Expand Down Expand Up @@ -331,7 +331,7 @@ public static SocketBase socket(Ctx ctx, int type)

private static void checkSocket(SocketBase s)
{
if (s == null || !s.checkTag()) {
if (s == null || !s.isActive()) {
throw new IllegalStateException();
}
}
Expand Down

0 comments on commit b04923b

Please sign in to comment.