diff options
author | stewart@willster.(none) <> | 2006-10-05 23:48:38 +1000 |
---|---|---|
committer | stewart@willster.(none) <> | 2006-10-05 23:48:38 +1000 |
commit | c637067f4dd528a6b52654c42170c30d2afa799e (patch) | |
tree | 6b36bd77ae82cc595c3def6163e85429967d6a7f /ndb/src/common | |
parent | 57dd1481aefd622f51c46e9a22abe06474e2801a (diff) | |
parent | c321ae2f0cf3f40da733b79d44b5acd9f9f84a91 (diff) | |
download | mariadb-git-c637067f4dd528a6b52654c42170c30d2afa799e.tar.gz |
Merge willster.(none):/home/stewart/Documents/MySQL/5.0/ndb
into willster.(none):/home/stewart/Documents/MySQL/5.0/bug13987-5.0_bugfixonly
Diffstat (limited to 'ndb/src/common')
-rw-r--r-- | ndb/src/common/util/InputStream.cpp | 39 | ||||
-rw-r--r-- | ndb/src/common/util/Parser.cpp | 35 | ||||
-rw-r--r-- | ndb/src/common/util/socket_io.cpp | 28 |
3 files changed, 58 insertions, 44 deletions
diff --git a/ndb/src/common/util/InputStream.cpp b/ndb/src/common/util/InputStream.cpp index 410e9a70e9c..1b0e809a047 100644 --- a/ndb/src/common/util/InputStream.cpp +++ b/ndb/src/common/util/InputStream.cpp @@ -36,26 +36,35 @@ FileInputStream::gets(char * buf, int bufLen){ SocketInputStream::SocketInputStream(NDB_SOCKET_TYPE socket, unsigned readTimeout) - : m_socket(socket) { - m_timeout = readTimeout; + : m_socket(socket) { + m_startover= true; + m_timeout = readTimeout; } -char* +char* SocketInputStream::gets(char * buf, int bufLen) { - buf[0] = 77; assert(bufLen >= 2); - int res = readln_socket(m_socket, m_timeout, buf, bufLen - 1); + int offset= 0; + if(m_startover) + { + buf[0]= '\0'; + m_startover= false; + } + else + offset= strlen(buf); + + int res = readln_socket(m_socket, m_timeout, buf+offset, bufLen-offset); + + if(res == 0) + { + buf[0]=0; + return buf; + } + + m_startover= true; + if(res == -1) return 0; - if(res == 0 && buf[0] == 77){ // select return 0 - buf[0] = 0; - } else if(res == 0 && buf[0] == 0){ // only newline - buf[0] = '\n'; - buf[1] = 0; - } else { - int len = strlen(buf); - buf[len + 1] = '\0'; - buf[len] = '\n'; - } + return buf; } diff --git a/ndb/src/common/util/Parser.cpp b/ndb/src/common/util/Parser.cpp index 3a86ae8f318..392c3e83825 100644 --- a/ndb/src/common/util/Parser.cpp +++ b/ndb/src/common/util/Parser.cpp @@ -148,21 +148,26 @@ ParserImpl::run(Context * ctx, const class Properties ** pDst, bool ownStop = false; if(stop == 0) stop = &ownStop; - + ctx->m_aliasUsed.clear(); - + const unsigned sz = sizeof(ctx->m_tokenBuffer); ctx->m_currentToken = input.gets(ctx->m_tokenBuffer, sz); if(Eof(ctx->m_currentToken)){ ctx->m_status = Parser<Dummy>::Eof; DBUG_RETURN(false); } - - if(ctx->m_currentToken[0] == 0){ + + int last= strlen(ctx->m_currentToken); + if(last>0) + last--; + + if(ctx->m_currentToken[last] !='\n'){ ctx->m_status = Parser<Dummy>::NoLine; + ctx->m_tokenBuffer[0]= '\0'; DBUG_RETURN(false); } - + if(Empty(ctx->m_currentToken)){ ctx->m_status = Parser<Dummy>::EmptyLine; DBUG_RETURN(false); @@ -174,14 +179,14 @@ ParserImpl::run(Context * ctx, const class Properties ** pDst, ctx->m_status = Parser<Dummy>::UnknownCommand; DBUG_RETURN(false); } - + Properties * p = new Properties(); - + bool invalidArgument = false; ctx->m_currentToken = input.gets(ctx->m_tokenBuffer, sz); - - while((! * stop) && - !Eof(ctx->m_currentToken) && + + while((! * stop) && + !Eof(ctx->m_currentToken) && !Empty(ctx->m_currentToken)){ if(ctx->m_currentToken[0] != 0){ trim(ctx->m_currentToken); @@ -193,7 +198,7 @@ ParserImpl::run(Context * ctx, const class Properties ** pDst, } ctx->m_currentToken = input.gets(ctx->m_tokenBuffer, sz); } - + if(invalidArgument){ char buf[sz]; char * tmp; @@ -204,13 +209,13 @@ ParserImpl::run(Context * ctx, const class Properties ** pDst, } DBUG_RETURN(false); } - + if(* stop){ delete p; ctx->m_status = Parser<Dummy>::ExternalStop; DBUG_RETURN(false); } - + if(!checkMandatory(ctx, p)){ ctx->m_status = Parser<Dummy>::MissingMandatoryArgument; delete p; @@ -226,9 +231,9 @@ ParserImpl::run(Context * ctx, const class Properties ** pDst, tmp.put("name", alias->name); tmp.put("realName", alias->realName); p->put("$ALIAS", i, &tmp); - } + } p->put("$ALIAS", ctx->m_aliasUsed.size()); - + ctx->m_status = Parser<Dummy>::Ok; * pDst = p; DBUG_RETURN(true); diff --git a/ndb/src/common/util/socket_io.cpp b/ndb/src/common/util/socket_io.cpp index 58636e6663d..ba2794e4374 100644 --- a/ndb/src/common/util/socket_io.cpp +++ b/ndb/src/common/util/socket_io.cpp @@ -75,7 +75,6 @@ readln_socket(NDB_SOCKET_TYPE socket, int timeout_millis, return -1; } - buf[0] = 0; const int t = recv(socket, buf, buflen, MSG_PEEK); if(t < 1) @@ -87,27 +86,28 @@ readln_socket(NDB_SOCKET_TYPE socket, int timeout_millis, for(int i=0; i< t;i++) { if(buf[i] == '\n'){ - recv(socket, buf, i+1, 0); - buf[i] = 0; + int r= recv(socket, buf, i+1, 0); + buf[i+1]= 0; + if(r < 1) { + fcntl(socket, F_SETFL, sock_flags); + return -1; + } if(i > 0 && buf[i-1] == '\r'){ - i--; - buf[i] = 0; + buf[i-1] = '\n'; + buf[i]= '\0'; } fcntl(socket, F_SETFL, sock_flags); - return t; + return r; } } - if(t == (buflen - 1)){ - recv(socket, buf, t, 0); - buf[t] = 0; - fcntl(socket, F_SETFL, sock_flags); - return buflen; - } - - return 0; + int r= recv(socket, buf, t, 0); + if(r>=0) + buf[r] = 0; + fcntl(socket, F_SETFL, sock_flags); + return r; } extern "C" |