diff options
author | scw <scw@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> | 2005-09-02 21:15:30 +0800 |
---|---|---|
committer | scw <scw@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> | 2005-09-02 21:15:30 +0800 |
commit | cbaa24d062e1ecebc90fd8b671a1c68daa70664b (patch) | |
tree | 450ca077745908fdc553801afc6be0a20e1b5236 /mbbsd | |
parent | 947b76093a20c3f08f774bf8a4a03e7688b29927 (diff) | |
download | pttbbs-cbaa24d062e1ecebc90fd8b671a1c68daa70664b.tar pttbbs-cbaa24d062e1ecebc90fd8b671a1c68daa70664b.tar.gz pttbbs-cbaa24d062e1ecebc90fd8b671a1c68daa70664b.tar.bz2 pttbbs-cbaa24d062e1ecebc90fd8b671a1c68daa70664b.tar.lz pttbbs-cbaa24d062e1ecebc90fd8b671a1c68daa70664b.tar.xz pttbbs-cbaa24d062e1ecebc90fd8b671a1c68daa70664b.tar.zst pttbbs-cbaa24d062e1ecebc90fd8b671a1c68daa70664b.zip |
* refine chess framework IO routines
* don't write data to user socket when there is no opposite
git-svn-id: http://opensvn.csie.org/pttbbs/trunk/pttbbs@3124 63ad8ddf-47c3-0310-b6dd-a9e9d9715204
Diffstat (limited to 'mbbsd')
-rw-r--r-- | mbbsd/chess.c | 43 |
1 files changed, 24 insertions, 19 deletions
diff --git a/mbbsd/chess.c b/mbbsd/chess.c index 900b39c7..72632357 100644 --- a/mbbsd/chess.c +++ b/mbbsd/chess.c @@ -254,28 +254,17 @@ ChessSendMove(ChessInfo* info, int sock, const void *step) return 1; } -ChessStepType -ChessStepReceive(ChessInfo* info, void* step) -{ - ChessStepType result = ChessRecvMove(info, info->sock, step); - - /* automatical routing */ - if (result != CHESS_STEP_FAILURE) - ChessStepBroadcast(info, step); - - /* and logging */ - if (result == CHESS_STEP_NORMAL) - ChessHistoryAppend(info, step); - - return result; -} - -int +inline static int ChessStepSendOpposite(ChessInfo* info, const void* step) { void (*orig_handler)(int); int result = 1; - + + /* fd 0 is the socket to user, it means no oppisite available. + * (Might be personal play) */ + if (info->sock == 0) + return 1; + orig_handler = Signal(SIGPIPE, SIG_IGN); if (!ChessSendMove(info, info->sock, step)) @@ -285,7 +274,7 @@ ChessStepSendOpposite(ChessInfo* info, const void* step) return result; } -void +inline static void ChessStepBroadcast(ChessInfo* info, const void *step) { ChessBroadcastListNode *p = &(info->broadcast_list.head); @@ -325,6 +314,22 @@ ChessMessageSend(ChessInfo* info, ChessStepType type) return ChessStepSend(info, &type); } +ChessStepType +ChessStepReceive(ChessInfo* info, void* step) +{ + ChessStepType result = ChessRecvMove(info, info->sock, step); + + /* automatical routing */ + if (result != CHESS_STEP_FAILURE) + ChessStepBroadcast(info, step); + + /* and logging */ + if (result == CHESS_STEP_NORMAL) + ChessHistoryAppend(info, step); + + return result; +} + inline static void ChessReplayUntil(ChessInfo* info, int n) { |