|
View:
New views
5 Messages
—
Rating Filter:
Alert me
|
|
|
seeking advice on my POSIX wrapperHello,
Last night I sent out an announcement about some POSIX work that I have been doing. In any case, one of the FFI wrappers is driving me crazy, i.e. the one for mq_receive:http://opengroup.org/onlinepubs/007908799/xsh/mq_receive.html . When I call this function (mqReceive), I get "message too long". In my test cases I am sending and receiving messages that are only 11 bytes! The wrapper seems really straightforward. Perhaps I am looking right at the problem and don't see. I need other eyes on the wrapper to help me ;^). Please see below. Regards, V. ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -- mqReceive is still being debugged!!!!!!!!!! -- | Retrieve a message from mqueue designated by "mqd" -- mqReceive :: Fd -> ByteCount -> Maybe Int -> IO (String, Int) mqReceive (Fd mqd) len (Just prio) = do allocaBytes (fromIntegral len) $ \ p_buffer -> do with (fromIntegral prio) $ \ p_prio -> do rc <- throwErrnoIfMinus1 "mqReceive" (c_mq_receive mqd p_buffer (fromIntegral len) p_prio) case fromIntegral rc of 0 -> ioError (IOError Nothing EOF "mqReceive" "EOF" Nothing) n -> do s <- peekCStringLen (p_buffer, fromIntegral n) return (s, n) mqReceive (Fd mqd) len Nothing = do allocaBytes (fromIntegral len) $ \ p_buffer -> do rc <- throwErrnoIfMinus1 "mqReceive" (c_mq_receive mqd p_buffer (fromIntegral len) nullPtr) case fromIntegral rc of 0 -> ioError (IOError Nothing EOF "mqReceive" "EOF" Nothing) n -> do s <- peekCStringLen (p_buffer, fromIntegral n) return (s, n) foreign import ccall unsafe "mqueue.h mq_receive" c_mq_receive :: CInt -> Ptr CChar -> CSize -> Ptr CInt -> IO CInt _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@... http://www.haskell.org/mailman/listinfo/haskell-cafe |
|
|
Re: seeking advice on my POSIX wrapperHello Vasili,
Sunday, May 11, 2008, 12:47:52 AM, you wrote: > . When I call this function (mqReceive), I get "message too long". you can divide-and-conquer the problem by trying 1) write the C code that calls mq_receive with the same params 2) call your own function instead of mq_receive and printf parameters it receives -- Best regards, Bulat mailto:Bulat.Ziganshin@... _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@... http://www.haskell.org/mailman/listinfo/haskell-cafe |
|
|
Re: seeking advice on my POSIX wrapperOn 2008 May 10, at 16:47, Galchin, Vasili wrote: Last night I sent out an announcement about some POSIX work that I have been doing. In any case, one of the FFI wrappers is driving me crazy, i.e. the one for mq_receive:http://opengroup.org/onlinepubs/007908799/xsh/mq_receive.html . When I call this function (mqReceive), I get "message too long". In my test cases I am sending and receiving messages that are only 11 bytes! The wrapper seems really straightforward. Perhaps I am looking right at the problem and don't see. I need other eyes on the wrapper to help me ;^). Please see below. What's the other end sending? I suspect most implementations of mq_receive() layer it on top of msgrcv(), which can return E2BIG (== EMSGSIZE) if the message to be received is larger than the receiving buffer --- a condition which I note mq_receive() does not document (unless mq_msgsize means a given queue only supports fixed size messages, which seems odd). -- brandon s. allbery [solaris,freebsd,perl,pugs,haskell] allbery@... system administrator [openafs,heimdal,too many hats] allbery@... electrical and computer engineering, carnegie mellon university KF8NH _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@... http://www.haskell.org/mailman/listinfo/haskell-cafe |
|
|
Re: seeking advice on my POSIX wrappersender ......
main = do fd <- mqOpen "/myipc" ReadWrite (Just nullFileMode) (Just (MQAttributes 0 128 128 0)) mqSend fd "Hello world" 11 1 (MQAttributes flags maxMsgNum maxMsgSize curNumMsgs) <- mqGetAttributes fd putStrLn ("attrs flags->" ++ (show flags) ++ " maxMsgNum -> " ++ (show maxMsgNum) ++ " maxMsgSize -> " ++ (show maxMsgSize) ++ " curNumMsgs -> " ++ (show curNumMsgs)) mqClose fd return fd ~ ----------------------------------------- receiver main = do fd <- mqOpen "/myipc" ReadWrite (Just nullFileMode) (Just (MQAttributes 0 128 128 0)) (MQAttributes flags maxMsgNum maxMsgSize curNumMsgs) <- mqGetAttributes fd putStrLn ("attrs flags->" ++ (show flags) ++ " maxMsgNum -> " ++ (show maxMsgNum) ++ " maxMsgSize -> " ++ (show maxMsgSize) ++ " curNumMsgs -> " ++ (show curNumMsgs)) (MQAttributes flags maxMsgNum maxMsgSize curNumMsgs) <- mqSetAttributes fd (MQAttributes{flags=0, maxMsgNum=127, maxMsgSize=127, curNumMsgs=7}) putStrLn ("attrs flags->" ++ (show flags) ++ " maxMsgNum -> " ++ (show maxMsgNum) ++ " maxMsgSize -> " ++ (show maxMsgSize) ++ " curNumMsgs -> " ++ (show curNumMsgs)) (s, n) <- mqReceive fd 60 Nothing putStrLn ("dump " ++ s) (s, n) <- mqReceive fd 11 (Just 1) putStrLn s mqClose fd -- mqUnlink "/myipc" return fd ~ --------------------------------------------------------------------------------------------------------------------------------------------- Thanks, Vasili
On Sat, May 10, 2008 at 4:09 PM, Brandon S. Allbery KF8NH <allbery@...> wrote:
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@... http://www.haskell.org/mailman/listinfo/haskell-cafe |
|
|
Re: seeking advice on my POSIX wrapperThe Linux version of mqueue that I am using is implemented as a Linux filesystem. I am reading now, Brandon.
V. On Sat, May 10, 2008 at 4:09 PM, Brandon S. Allbery KF8NH <allbery@...> wrote:
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@... http://www.haskell.org/mailman/listinfo/haskell-cafe |
| Free Forum Powered by Nabble | Forum Help |